- def mbox(self):
- postscript_re = re.compile('\n-{2,3} ?\n')
-
- comment = None
- try:
- comment = Comment.objects.get(patch = self, msgid = self.msgid)
- except Exception:
- pass
-
- body = ''
- if comment:
- body = comment.content.strip() + "\n"
-
- parts = postscript_re.split(body, 1)
- if len(parts) == 2:
- (body, postscript) = parts
- body = body.strip() + "\n"
- postscript = postscript.strip() + "\n"
- else:
- postscript = ''
-
- for comment in Comment.objects.filter(patch = self) \
- .exclude(msgid = self.msgid):
- body += comment.patch_responses()
-
- if body:
- body += '\n'
-
- if postscript:
- body += '---\n' + postscript.strip() + '\n'
-
- if self.content:
- body += '\n' + self.content
-
- utc_timestamp = (self.date -
- datetime.datetime.utcfromtimestamp(0)).total_seconds()
-
- mail = PatchMbox(body)
- mail['Subject'] = self.name
- mail['Date'] = email.utils.formatdate(utc_timestamp)
- mail['From'] = email.utils.formataddr((
- str(Header(self.submitter.name, mail.patch_charset)),
- self.submitter.email))
- mail['X-Patchwork-Id'] = str(self.id)
- mail['Message-Id'] = self.msgid
- mail.set_unixfrom('From patchwork ' + self.date.ctime())
-
-
- copied_headers = ['To', 'Cc']
- orig_headers = HeaderParser().parsestr(str(self.headers))
- for header in copied_headers:
- if header in orig_headers:
- mail[header] = orig_headers[header]
-
- return mail
-