+ if crt_addr:
+ msg[header] = address_or_alias(', '.join([crt_addr, addr]))
+ else:
+ msg[header] = address_or_alias(addr)
+
+ to_addr = ''
+ cc_addr = ''
+ bcc_addr = ''
+
+ autobcc = config.get('stgit.autobcc') or ''
+
+ if options.to:
+ to_addr = ', '.join(options.to)
+ if options.cc:
+ cc_addr = ', '.join(options.cc + extra_cc)
+ cc_addr = ', '.join(options.cc + extra_cc)
+ elif extra_cc:
+ cc_addr = ', '.join(extra_cc)
+ if options.bcc:
+ bcc_addr = ', '.join(options.bcc + [autobcc])
+ elif autobcc:
+ bcc_addr = autobcc
+
+ __replace_header('To', to_addr)
+ __replace_header('Cc', cc_addr)
+ __replace_header('Bcc', bcc_addr)
+
+def __get_signers_list(msg):
+ """Return the address list generated from signed-off-by and
+ acked-by lines in the message.
+ """
+ addr_list = []
+
+ r = re.compile('^(signed-off-by|acked-by|cc):\s+(.+)$', re.I)
+ for line in msg.split('\n'):
+ m = r.match(line)
+ if m:
+ addr_list.append(m.expand('\g<2>'))
+
+ return addr_list
+
+def __build_extra_headers(msg, msg_id, ref_id = None):
+ """Build extra email headers and encoding
+ """
+ del msg['Date']
+ msg['Date'] = email.Utils.formatdate(localtime = True)
+ msg['Message-ID'] = msg_id
+ if ref_id:
+ # make sure the ref id has the angle brackets
+ ref_id = '<%s>' % ref_id.strip(' \t\n<>')
+ msg['In-Reply-To'] = ref_id
+ msg['References'] = ref_id
+ msg['User-Agent'] = 'StGIT/%s' % version.version
+
+def __encode_message(msg):
+ # 7 or 8 bit encoding
+ charset = email.Charset.Charset('utf-8')
+ charset.body_encoding = None
+
+ # encode headers
+ for header, value in msg.items():
+ words = []
+ for word in value.split(' '):
+ try:
+ uword = unicode(word, 'utf-8')
+ except UnicodeDecodeError:
+ # maybe we should try a different encoding or report
+ # the error. At the moment, we just ignore it
+ pass
+ words.append(email.Header.Header(uword).encode())
+ new_val = ' '.join(words)
+ msg.replace_header(header, new_val)
+
+ # encode the body and set the MIME and encoding headers
+ if msg.is_multipart():
+ for p in msg.get_payload():
+ p.set_charset(charset)
+ else:
+ msg.set_charset(charset)
+
+def __edit_message(msg):
+ fname = '.stgitmail.txt'
+
+ # create the initial file
+ f = file(fname, 'w')
+ f.write(msg)
+ f.close()
+
+ call_editor(fname)
+
+ # read the message back
+ f = file(fname)
+ msg = f.read()
+ f.close()
+
+ return msg
+
+def __build_cover(tmpl, patches, msg_id, options):
+ """Build the cover message (series description) to be sent via SMTP
+ """
+ sender = __get_sender()
+
+ if options.version:
+ version_str = ' %s' % options.version
+ else:
+ version_str = ''
+
+ if options.prefix:
+ prefix_str = options.prefix + ' '
+ else:
+ confprefix = config.get('stgit.mail.prefix')
+ if confprefix:
+ prefix_str = confprefix + ' '
+ else:
+ prefix_str = ''
+
+ total_nr_str = str(len(patches))
+ patch_nr_str = '0'.zfill(len(total_nr_str))
+ if len(patches) > 1:
+ number_str = ' %s/%s' % (patch_nr_str, total_nr_str)
+ else:
+ number_str = ''
+
+ tmpl_dict = {'sender': sender,
+ # for backward template compatibility
+ 'maintainer': sender,
+ # for backward template compatibility
+ 'endofheaders': '',
+ # for backward template compatibility
+ 'date': '',
+ 'version': version_str,
+ 'prefix': prefix_str,
+ 'patchnr': patch_nr_str,
+ 'totalnr': total_nr_str,
+ 'number': number_str,
+ 'shortlog': stack.shortlog(crt_series.get_patch(p)
+ for p in patches),
+ 'diffstat': git.diffstat(git.diff(
+ rev1 = git_id(crt_series, '%s//bottom' % patches[0]),
+ rev2 = git_id(crt_series, '%s//top' % patches[-1])))}