+ __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))