~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-27 00:31:39 UTC
  • mfrom: (14033.1.3 non-active-user-bug-mail)
  • Revision ID: launchpad@pqm.canonical.com-20110927003139-qypu9zoto51d6epv
[r=benji][bug=38162] Do not permit users without preferred email
        addresses to use bug mail.

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,
209
210
        commands = self.getCommands(signed_msg)
210
211
        to_user, to_host = to_addr.split('@')
211
212
        add_comment_to_bug = False
 
213
        from_user = getUtility(ILaunchBag).user
 
214
        if to_user.lower() == 'help' or from_user is None:
 
215
            if from_user is not None and from_user.preferredemail is not None:
 
216
                to_address = str(from_user.preferredemail.email)
 
217
            else:
 
218
                to_address = signed_msg['From']
 
219
                address = getUtility(IEmailAddressSet).getByEmail(to_address)
 
220
                if address is None:
 
221
                    to_address = None
 
222
            if to_address is not None:
 
223
                self.sendHelpEmail(to_address)
 
224
            return True, False, None
212
225
        # If there are any commands, we must have strong authentication.
213
226
        # We send a different failure message for attempts to create a new
214
227
        # bug.
215
 
        if to_user.lower() == 'new':
 
228
        elif to_user.lower() == 'new':
216
229
            ensure_not_weakly_authenticated(signed_msg, CONTEXT,
217
230
                'unauthenticated-bug-creation.txt',
218
231
                error_templates=error_templates)
228
241
            # the bug.
229
242
            add_comment_to_bug = True
230
243
            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
244
        elif to_user.lower() != 'edit':
240
245
            # Indicate that we didn't handle the mail.
241
246
            return False, False, None