| OLD | NEW |
| 1 # Copyright 2008 Google Inc. | 1 # Copyright 2008 Google Inc. |
| 2 # | 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
| 6 # | 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 # See the License for the specific language governing permissions and | 12 # See the License for the specific language governing permissions and |
| 13 # limitations under the License. | 13 # limitations under the License. |
| 14 | 14 |
| 15 """Views for Rietveld.""" | 15 """Views for Rietveld.""" |
| 16 | 16 |
| 17 | 17 |
| 18 import binascii | 18 import binascii |
| 19 import datetime | 19 import datetime |
| 20 import email # see incoming_mail() | 20 import email # see incoming_mail() |
| 21 import email.utils | 21 import email.utils |
| 22 import logging | 22 import logging |
| 23 import md5 | 23 import md5 |
| 24 import mimetypes | 24 import mimetypes |
| 25 import os | 25 import os |
| 26 import random | 26 import random |
| 27 import re | 27 import re |
| 28 import urllib | 28 import urllib |
| 29 from cStringIO import StringIO | 29 from cStringIO import StringIO |
| 30 from email.header import decode_header |
| 30 from xml.etree import ElementTree | 31 from xml.etree import ElementTree |
| 31 | 32 |
| 32 from google.appengine.api import mail | 33 from google.appengine.api import mail |
| 33 from google.appengine.api import memcache | 34 from google.appengine.api import memcache |
| 34 from google.appengine.api import taskqueue | 35 from google.appengine.api import taskqueue |
| 35 from google.appengine.api import users | 36 from google.appengine.api import users |
| 36 from google.appengine.api import urlfetch | 37 from google.appengine.api import urlfetch |
| 37 from google.appengine.api import xmpp | 38 from google.appengine.api import xmpp |
| 38 from google.appengine.ext import db | 39 from google.appengine.ext import db |
| 39 from google.appengine.runtime import DeadlineExceededError | 40 from google.appengine.runtime import DeadlineExceededError |
| (...skipping 3861 matching lines...) | | Loading... |
| 3901 def _process_incoming_mail(raw_message, recipients): | 3902 def _process_incoming_mail(raw_message, recipients): |
| 3902 """Process an incoming email message.""" | 3903 """Process an incoming email message.""" |
| 3903 recipients = [x[1] for x in email.utils.getaddresses([recipients])] | 3904 recipients = [x[1] for x in email.utils.getaddresses([recipients])] |
| 3904 | 3905 |
| 3905 incoming_msg = mail.InboundEmailMessage(raw_message) | 3906 incoming_msg = mail.InboundEmailMessage(raw_message) |
| 3906 | 3907 |
| 3907 if 'X-Google-Appengine-App-Id' in incoming_msg.original: | 3908 if 'X-Google-Appengine-App-Id' in incoming_msg.original: |
| 3908 raise InvalidIncomingEmailError('Mail sent by App Engine') | 3909 raise InvalidIncomingEmailError('Mail sent by App Engine') |
| 3909 | 3910 |
| 3910 subject = incoming_msg.subject or '' | 3911 subject = incoming_msg.subject or '' |
| 3912 decoded_subject = decode_header(subject) |
| 3913 if decoded_subject[0][1]: |
| 3914 subject = decoded_subject[0][0].decode(decoded_subject[0][1]) |
| 3911 match = re.search(r'\(issue *(?P<id>\d+)\)$', subject) | 3915 match = re.search(r'\(issue *(?P<id>\d+)\)$', subject) |
| 3912 if match is None: | 3916 if match is None: |
| 3913 raise InvalidIncomingEmailError('No issue id found: %s', subject) | 3917 raise InvalidIncomingEmailError('No issue id found: %s', subject) |
| 3914 issue_id = int(match.groupdict()['id']) | 3918 issue_id = int(match.groupdict()['id']) |
| 3915 issue = models.Issue.get_by_id(issue_id) | 3919 issue = models.Issue.get_by_id(issue_id) |
| 3916 if issue is None: | 3920 if issue is None: |
| 3917 raise InvalidIncomingEmailError('Unknown issue ID: %d' % issue_id) | 3921 raise InvalidIncomingEmailError('Unknown issue ID: %d' % issue_id) |
| 3918 sender = email.utils.parseaddr(incoming_msg.sender)[1] | 3922 sender = email.utils.parseaddr(incoming_msg.sender)[1] |
| 3919 | 3923 |
| 3920 body = None | 3924 body = None |
| (...skipping 115 matching lines...) | | Loading... |
| 4036 patchsets = None | 4040 patchsets = None |
| 4037 for patch in patchset.patch_set.filter('delta_calculated =', False): | 4041 for patch in patchset.patch_set.filter('delta_calculated =', False): |
| 4038 if patchsets is None: | 4042 if patchsets is None: |
| 4039 # patchsets is retrieved on first iteration because patchsets | 4043 # patchsets is retrieved on first iteration because patchsets |
| 4040 # isn't needed outside the loop at all. | 4044 # isn't needed outside the loop at all. |
| 4041 patchsets = list(patchset.issue.patchset_set.order('created')) | 4045 patchsets = list(patchset.issue.patchset_set.order('created')) |
| 4042 patch.delta = _calculate_delta(patch, patchset_id, patchsets) | 4046 patch.delta = _calculate_delta(patch, patchset_id, patchsets) |
| 4043 patch.delta_calculated = True | 4047 patch.delta_calculated = True |
| 4044 patch.put() | 4048 patch.put() |
| 4045 return HttpResponse() | 4049 return HttpResponse() |
| OLD | NEW |