~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-08-13 01:11:42 UTC
  • mfrom: (13668.1.31 private-bug-0)
  • Revision ID: launchpad@pqm.canonical.com-20110813011142-b8xvpxhdja422ln2
[rs=sinzui][no-qa] Moved canonical.launchpad.mail to lp.services.mail,
 bugs.mail, code.mail.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2010 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
"""Handle incoming Bugs email."""
8
8
    "MaloneHandler",
9
9
    ]
10
10
 
 
11
import os
 
12
 
11
13
from lazr.lifecycle.event import ObjectCreatedEvent
12
14
from lazr.lifecycle.interfaces import IObjectCreatedEvent
13
15
from zope.component import getUtility
16
18
 
17
19
from canonical.database.sqlbase import rollback
18
20
from canonical.launchpad.helpers import get_email_template
19
 
from canonical.launchpad.interfaces.mail import (
20
 
    EmailProcessingError,
21
 
    IBugEditEmailCommand,
22
 
    IBugEmailCommand,
23
 
    IBugTaskEditEmailCommand,
24
 
    IBugTaskEmailCommand,
25
 
    IMailHandler,
26
 
    )
27
 
from lp.services.messages.interfaces.message import IMessageSet
28
 
from canonical.launchpad.mail.commands import (
29
 
    BugEmailCommands,
30
 
    get_error_message,
31
 
    )
32
 
from canonical.launchpad.mail.helpers import (
33
 
    ensure_not_weakly_authenticated,
34
 
    get_main_body,
35
 
    guess_bugtask,
36
 
    IncomingEmailError,
37
 
    parse_commands,
38
 
    reformat_wiki_text,
39
 
    )
40
21
from canonical.launchpad.mailnotification import (
41
22
    MailWrapper,
42
23
    send_process_error_notification,
48
29
    IBugAttachmentSet,
49
30
    )
50
31
from lp.bugs.interfaces.bugmessage import IBugMessageSet
 
32
from lp.bugs.mail.commands import BugEmailCommands
 
33
from lp.services.mail.helpers import (
 
34
    ensure_not_weakly_authenticated,
 
35
    get_error_message,
 
36
    get_main_body,
 
37
    guess_bugtask,
 
38
    IncomingEmailError,
 
39
    parse_commands,
 
40
    reformat_wiki_text,
 
41
    )
 
42
from lp.services.mail.interfaces import (
 
43
    EmailProcessingError,
 
44
    IBugEditEmailCommand,
 
45
    IBugEmailCommand,
 
46
    IBugTaskEditEmailCommand,
 
47
    IBugTaskEmailCommand,
 
48
    IMailHandler,
 
49
    )
51
50
from lp.services.mail.sendmail import simple_sendmail
 
51
from lp.services.messages.interfaces.message import IMessageSet
 
52
 
 
53
 
 
54
error_templates = os.path.join(os.path.dirname(__file__), 'errortemplates')
52
55
 
53
56
 
54
57
class MaloneHandler:
93
96
        # bug.
94
97
        if to_user.lower() == 'new':
95
98
            ensure_not_weakly_authenticated(signed_msg, CONTEXT,
96
 
                'unauthenticated-bug-creation.txt')
 
99
                'unauthenticated-bug-creation.txt',
 
100
                error_templates=error_templates)
97
101
        elif len(commands) > 0:
98
102
            ensure_not_weakly_authenticated(signed_msg, CONTEXT)
99
103
        if to_user.lower() == 'new':
146
150
                                rollback()
147
151
                                raise IncomingEmailError(
148
152
                                    get_error_message(
149
 
                                        'no-affects-target-on-submit.txt'))
 
153
                                        'no-affects-target-on-submit.txt',
 
154
                                        error_templates=error_templates))
150
155
                        if (bugtask_event is not None and
151
156
                            not IObjectCreatedEvent.providedBy(bug_event)):
152
157
                            notify(bugtask_event)
200
205
                                rollback()
201
206
                                raise IncomingEmailError(
202
207
                                    get_error_message(
203
 
                                        'no-affects-target-on-submit.txt'))
 
208
                                        'no-affects-target-on-submit.txt',
 
209
                                        error_templates=error_templates))
204
210
                            bugtask = guess_bugtask(
205
211
                                bug, getUtility(ILaunchBag).user)
206
212
                            if bugtask is None:
207
213
                                raise IncomingEmailError(get_error_message(
208
214
                                    'no-default-affects.txt',
 
215
                                    error_templates=error_templates,
209
216
                                    bug_id=bug.id,
210
217
                                    nr_of_bugtasks=len(bug.bugtasks)))
211
218
                        bugtask, bugtask_event = command.execute(
231
238
                except CreatedBugWithNoBugTasksError:
232
239
                    rollback()
233
240
                    raise IncomingEmailError(
234
 
                        get_error_message('no-affects-target-on-submit.txt'))
 
241
                        get_error_message(
 
242
                            'no-affects-target-on-submit.txt',
 
243
                            error_templates=error_templates))
235
244
            if bugtask_event is not None:
236
245
                if not IObjectCreatedEvent.providedBy(bug_event):
237
246
                    notify(bugtask_event)
274
283
    # seem to store no more than an RTF representation of an email.
275
284
 
276
285
    irrelevant_content_types = set((
277
 
        'application/applefile', # the resource fork of a MacOS file
 
286
        'application/applefile',  # the resource fork of a MacOS file
278
287
        'application/pgp-signature',
279
288
        'application/pkcs7-signature',
280
289
        'application/x-pkcs7-signature',