~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/mail/handler.py

  • Committer: Stuart Bishop
  • Date: 2011-09-28 12:49:24 UTC
  • mfrom: (9893.10.1 trivial)
  • mto: This revision was merged to the branch mainline in revision 14178.
  • Revision ID: stuart.bishop@canonical.com-20110928124924-m5a22fymqghw6c5i
Merged trivial into distinct-db-users.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from zope.interface import implements
20
20
 
21
21
from canonical.launchpad.helpers import get_email_template
 
22
from canonical.launchpad.interfaces.emailaddress import IEmailAddressSet
22
23
from canonical.launchpad.mailnotification import (
23
24
    MailWrapper,
24
25
    send_process_error_notification,
25
26
    )
26
27
from canonical.launchpad.webapp.interfaces import ILaunchBag
27
 
from lp.bugs.interfaces.bug import CreatedBugWithNoBugTasksError
 
28
from lp.bugs.interfaces.bug import (
 
29
    CreateBugParams,
 
30
    CreatedBugWithNoBugTasksError,
 
31
    )
28
32
from lp.bugs.interfaces.bugattachment import (
29
33
    BugAttachmentType,
30
34
    IBugAttachmentSet,
31
35
    )
32
36
from lp.bugs.interfaces.bugmessage import IBugMessageSet
33
 
from lp.bugs.interfaces.bug import CreateBugParams
34
37
from lp.bugs.mail.commands import BugEmailCommands
35
38
from lp.services.mail.helpers import (
36
39
    ensure_not_weakly_authenticated,
209
212
        commands = self.getCommands(signed_msg)
210
213
        to_user, to_host = to_addr.split('@')
211
214
        add_comment_to_bug = False
 
215
        from_user = getUtility(ILaunchBag).user
 
216
        if to_user.lower() == 'help' or from_user is None:
 
217
            if from_user is not None and from_user.preferredemail is not None:
 
218
                to_address = str(from_user.preferredemail.email)
 
219
            else:
 
220
                to_address = signed_msg['From']
 
221
                address = getUtility(IEmailAddressSet).getByEmail(to_address)
 
222
                if address is None:
 
223
                    to_address = None
 
224
            if to_address is not None:
 
225
                self.sendHelpEmail(to_address)
 
226
            return True, False, None
212
227
        # If there are any commands, we must have strong authentication.
213
228
        # We send a different failure message for attempts to create a new
214
229
        # bug.
215
 
        if to_user.lower() == 'new':
 
230
        elif to_user.lower() == 'new':
216
231
            ensure_not_weakly_authenticated(signed_msg, CONTEXT,
217
232
                'unauthenticated-bug-creation.txt',
218
233
                error_templates=error_templates)
228
243
            # the bug.
229
244
            add_comment_to_bug = True
230
245
            commands.insert(0, BugEmailCommands.get('bug', [to_user]))
231
 
        elif to_user.lower() == 'help':
232
 
            from_user = getUtility(ILaunchBag).user
233
 
            if from_user is not None:
234
 
                preferredemail = from_user.preferredemail
235
 
                if preferredemail is not None:
236
 
                    to_address = str(preferredemail.email)
237
 
                    self.sendHelpEmail(to_address)
238
 
            return True, False, None
239
246
        elif to_user.lower() != 'edit':
240
247
            # Indicate that we didn't handle the mail.
241
248
            return False, False, None