# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from django.http import Http404
+from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.shortcuts import render_to_response
from patchwork.compat import reverse
from patchwork.models import CoverLetter
from patchwork.models import Submission
+from patchwork.views.utils import cover_to_mbox
def cover_detail(request, cover_id):
}
return render_to_response('patchwork/submission.html', context)
+
+
+def cover_mbox(request, cover_id):
+ cover = get_object_or_404(CoverLetter, id=cover_id)
+
+ response = HttpResponse(content_type='text/plain')
+ response.write(cover_to_mbox(cover))
+ response['Content-Disposition'] = 'attachment; filename=%s.mbox' % (
+ cover.filename)
+
+ return response
from django.utils import six
from patchwork.models import Comment
+from patchwork.models import Patch
from patchwork.models import Series
encode_7or8bit(self)
-def patch_to_mbox(patch):
- """Get an mbox representation of a single patch.
+def _submission_to_mbox(submission):
+ """Get an mbox representation of a single Submission.
+
+ Handles both Patch and CoverLetter objects.
Arguments:
- patch: The Patch object to convert.
+ submission: The Patch object to convert.
Returns:
A string for the mbox file.
"""
+ is_patch = isinstance(submission, Patch)
+
postscript_re = re.compile('\n-{2,3} ?\n')
body = ''
- if patch.content:
- body = patch.content.strip() + "\n"
+ if submission.content:
+ body = submission.content.strip() + "\n"
parts = postscript_re.split(body, 1)
if len(parts) == 2:
postscript = ''
# TODO(stephenfin): Make this use the tags infrastructure
- for comment in Comment.objects.filter(submission=patch):
+ for comment in Comment.objects.filter(submission=submission):
body += comment.patch_responses
if postscript:
body += '---\n' + postscript + '\n'
- if patch.diff:
- body += '\n' + patch.diff
+ if is_patch and submission.diff:
+ body += '\n' + submission.diff
- delta = patch.date - datetime.datetime.utcfromtimestamp(0)
+ delta = submission.date - datetime.datetime.utcfromtimestamp(0)
utc_timestamp = delta.seconds + delta.days * 24 * 3600
mail = PatchMbox(body)
- mail['Subject'] = patch.name
+ mail['Subject'] = submission.name
mail['X-Patchwork-Submitter'] = email.utils.formataddr((
- str(Header(patch.submitter.name, mail.patch_charset)),
- patch.submitter.email))
- mail['X-Patchwork-Id'] = str(patch.id)
- if patch.delegate:
- mail['X-Patchwork-Delegate'] = str(patch.delegate.email)
- mail['Message-Id'] = patch.msgid
- mail.set_unixfrom('From patchwork ' + patch.date.ctime())
+ str(Header(submission.submitter.name, mail.patch_charset)),
+ submission.submitter.email))
+ mail['X-Patchwork-Id'] = str(submission.id)
+ if is_patch and submission.delegate:
+ mail['X-Patchwork-Delegate'] = str(submission.delegate.email)
+ mail['Message-Id'] = submission.msgid
+ mail.set_unixfrom('From patchwork ' + submission.date.ctime())
copied_headers = ['To', 'Cc', 'Date', 'From', 'List-Id']
- orig_headers = HeaderParser().parsestr(str(patch.headers))
+ orig_headers = HeaderParser().parsestr(str(submission.headers))
for header in copied_headers:
if header in orig_headers:
mail[header] = orig_headers[header]
return mail
+patch_to_mbox = _submission_to_mbox
+cover_to_mbox = _submission_to_mbox
+
+
def bundle_to_mbox(bundle):
"""Get an mbox representation of a bundle.