+
+def __parse_description(descr):
+ """Parse the patch description and return the new description and
+ author information (if any).
+ """
+ subject = body = ''
+ authname = authemail = None
+
+ descr_lines = [line.strip() for line in descr.split('\n')]
+ if not descr_lines:
+ raise CmdException, "Empty patch description"
+
+ pos = 1
+ end = len(descr_lines)
+
+ # get the subject
+ subject = descr_lines[0]
+
+ # ignore the empty lines after subject
+ while pos < end and descr_lines[pos] == '':
+ pos += 1
+
+ # check for a "From:" line
+ if pos < end and re.match('from:\s+', descr_lines[pos], re.I):
+ auth = re.findall('^.*?:\s+(.*)$', descr_lines[pos])[0]
+ authname, authemail = name_email(auth)
+ pos += 1
+
+ # ignore the empty lines
+ while pos < end and descr_lines[pos] == '':
+ pos += 1
+
+ # get the body
+ body = reduce(lambda x, y: x + '\n' + y, descr_lines[pos:], '').strip()
+
+ return (subject + '\n\n' + body, authname, authemail)
+