X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/e3e05587390305008b3a832f0f62b4c81adacfda..1fceece7011fb0c32181d4e2128a871b09651b01:/stgit/commands/mail.py diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py index 6c761bd..975f8c9 100644 --- a/stgit/commands/mail.py +++ b/stgit/commands/mail.py @@ -124,18 +124,18 @@ def __get_maintainer(): else: return None -def __parse_addresses(string): +def __parse_addresses(addresses): """Return a two elements tuple: (from, [to]) """ - def __addr_list(string): - m = re.search('[^@\s<,]+@[^>\s,]+', string); - if (m == None): - return [] - return [ m.group() ] + __addr_list(string[m.end():]) + def __addr_list(addrs): + m = re.search('[^@\s<,]+@[^>\s,]+', addrs); + if (m == None): + return [] + return [ m.group() ] + __addr_list(addrs[m.end():]) from_addr_list = [] to_addr_list = [] - for line in string.split('\n'): + for line in addresses.split('\n'): if re.match('from:\s+', line, re.I): from_addr_list += __addr_list(line) elif re.match('(to|cc|bcc):\s+', line, re.I): @@ -174,20 +174,20 @@ def __send_message(smtpserver, from_addr, to_addr_list, msg, sleep, def __build_address_headers(options): headers_end = '' if options.to: - headers_end += 'To: ' - for to in options.to: - headers_end += '%s,' % to - headers_end = headers_end[:-1] + '\n' + headers_end += 'To: ' + for to in options.to: + headers_end += '%s, ' % to + headers_end = headers_end[:-2] + '\n' if options.cc: - headers_end += 'Cc: ' - for cc in options.cc: - headers_end += '%s,' % cc - headers_end = headers_end[:-1] + '\n' + headers_end += 'Cc: ' + for cc in options.cc: + headers_end += '%s, ' % cc + headers_end = headers_end[:-2] + '\n' if options.bcc: - headers_end += 'Bcc: ' - for bcc in options.bcc: - headers_end += '%s,' % bcc - headers_end = headers_end[:-1] + '\n' + headers_end += 'Bcc: ' + for bcc in options.bcc: + headers_end += '%s, ' % bcc + headers_end = headers_end[:-2] + '\n' return headers_end def __build_cover(tmpl, total_nr, msg_id, options): @@ -199,6 +199,9 @@ def __build_cover(tmpl, total_nr, msg_id, options): headers_end = __build_address_headers(options) headers_end += 'Message-Id: %s\n' % msg_id + if options.refid: + headers_end += "In-Reply-To: %s\n" % options.refid + headers_end += "References: %s\n" % options.refid if options.version: version_str = ' %s' % options.version @@ -341,12 +344,15 @@ def func(parser, options, args): smtppassword = config.get('stgit', 'smtppassword') applied = crt_series.get_applied() + unapplied = crt_series.get_unapplied() if len(args) >= 1: for patch in args: - if not patch in applied: + if patch in unapplied: raise CmdException, 'Patch "%s" not applied' % patch - patches = args + if not patch in applied: + raise CmdException, 'Patch "%s" does not exist' % patch + patches = args elif options.all: patches = applied elif options.range: @@ -369,11 +375,17 @@ def func(parser, options, args): if start in applied: start_idx = applied.index(start) else: - raise CmdException, 'Patch "%s" not applied' % start + if start in unapplied: + raise CmdException, 'Patch "%s" not applied' % start + else: + raise CmdException, 'Patch "%s" does not exist' % start if stop in applied: stop_idx = applied.index(stop) + 1 else: - raise CmdException, 'Patch "%s" not applied' % stop + if stop in unapplied: + raise CmdException, 'Patch "%s" not applied' % stop + else: + raise CmdException, 'Patch "%s" does not exist' % stop if start_idx >= stop_idx: raise CmdException, 'Incorrect patch range order' @@ -410,7 +422,7 @@ def func(parser, options, args): if options.cover: tfile_list = [options.cover] else: - tfile_list = [os.path.join(git.base_dir, 'covermail.tmpl'), + tfile_list = [os.path.join(git.get_base_dir(), 'covermail.tmpl'), os.path.join(sys.prefix, 'share/stgit/templates/covermail.tmpl')] @@ -441,7 +453,7 @@ def func(parser, options, args): if options.template: tfile_list = [options.template] else: - tfile_list = [os.path.join(git.base_dir, 'patchmail.tmpl'), + tfile_list = [os.path.join(git.get_base_dir(), 'patchmail.tmpl'), os.path.join(sys.prefix, 'share/stgit/templates/patchmail.tmpl')] tmpl = None