+ r = re.compile('^(signed-off-by|acked-by):\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:
+ 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
+ msg.set_charset(charset)
+
+def __edit_message(msg):
+ fname = '.stgitmail.txt'
+
+ # create the initial file
+ f = file(fname, 'w')
+ f.write(msg)
+ f.close()
+
+ # the editor
+ editor = config.get('stgit.editor')
+ if editor:
+ pass
+ elif 'EDITOR' in os.environ:
+ editor = os.environ['EDITOR']
+ else:
+ editor = 'vi'
+ editor += ' %s' % fname
+
+ print 'Invoking the editor: "%s"...' % editor,
+ sys.stdout.flush()
+ print 'done (exit code: %d)' % os.system(editor)
+
+ # read the message back
+ f = file(fname)
+ msg = f.read()
+ f.close()
+
+ return msg