@@ -22,12 +22,19 @@ from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.contrib.sites.models import Site
from django.conf import settings
+from patchwork.emailutils import clean_header, parse_from
from patchwork.parser import hash_patch
import re
import datetime, time
import random
+try:
+ from email.parser import HeaderParser
+except ImportError:
+ # Python 2.4 compatibility
+ from email.Parser import HeaderParser
+
class Person(models.Model):
email = models.CharField(max_length=255, unique = True)
name = models.CharField(max_length=255, null = True, blank = True)
@@ -197,6 +204,23 @@ class Patch(models.Model):
def comments(self):
return Comment.objects.filter(patch = self)
+ def sent_from(self):
+ """Return who the patch was sent from.
+
+ We'll use the raw header (but decoded to Unicode) since that's what will
+ be in the .patch file that's applied by the user.
+
+ @return: A unicode string representing the "From" of the original email.
+ """
+ orig_headers = HeaderParser().parsestr(str(self.headers))
+ return clean_header(orig_headers.get('From'))
+
+ def need_sent_from(self):
+ """Return true if the name in the "From" doesn't match the submitter."""
+ orig_headers = HeaderParser().parsestr(str(self.headers))
+ name, _ = parse_from(orig_headers.get('From'))
+ return name != self.submitter.name
+
def save(self):
try:
s = self.state
The sent_from will return the actual name/address that a patch was sent from. This is useful in the case where the patchwork "Submitter" name doesn't match the name that was actually associated with the patch (even though the email address must match). The need_sent_from() tells you when we need to include the "sent_from" because the patchwork Submitter name didn't match the name associated with the patch. Signed-off-by: Doug Anderson <dianders@chromium.org> --- apps/patchwork/models.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)