~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mail_client.py

  • Committer: Aaron Bentley
  • Date: 2009-05-11 18:35:20 UTC
  • mto: This revision was merged to the branch mainline in revision 4351.
  • Revision ID: aaron@aaronbentley.com-20090511183520-xtvepoauy7zjtb7x
Move hook to MergeDirective, implement MergeDirective.compose_merge_request.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from bzrlib import (
26
26
    email_message,
27
27
    errors,
28
 
    hooks,
29
28
    msgeditor,
30
29
    osutils,
31
30
    urlutils,
35
34
mail_client_registry = registry.Registry()
36
35
 
37
36
 
38
 
class MailClientHooks(hooks.Hooks):
39
 
 
40
 
    def __init__(self):
41
 
        hooks.Hooks.__init__(self)
42
 
        self.create_hook(hooks.HookPoint('merge_request_body',
43
 
            "Called with a MergeRequestBodyParams when a body is needed for"
44
 
            " a merge request.  Callbacks must return a body.  If more"
45
 
            " than one callback is registered, the output of one callback is"
46
 
            " provided to the next.", (1, 15, 0), False))
47
 
 
48
 
 
49
37
class MailClient(object):
50
38
    """A mail client that can send messages with attachements."""
51
39
 
52
 
    hooks = MailClientHooks()
53
 
 
54
40
    def __init__(self, config):
55
41
        self.config = config
56
42
 
86
72
        :param basename: The name to use for the attachment, e.g.
87
73
            "send-nick-3252"
88
74
        """
89
 
        orig_body = body
90
75
        prompt = self._get_merge_prompt("Please describe these changes:", to,
91
76
                                        subject, directive)
92
 
        for hook in self.hooks['merge_request_body']:
93
 
            params = MergeRequestBodyParams(body, orig_body, directive,
94
 
                                            to, basename, subject)
95
 
            body = hook(params)
96
77
        self.compose(prompt, to, subject, directive,
97
78
            'x-patch', '.patch', basename, body)
98
79
 
107
88
        return ''
108
89
 
109
90
 
110
 
class MergeRequestBodyParams(object):
111
 
 
112
 
    def __init__(self, body, orig_body, directive, to, basename, subject):
113
 
        self.body = body
114
 
        self.orig_body = orig_body
115
 
        self.directive = directive
116
 
        self.to = to
117
 
        self.basename = basename
118
 
        self.subject = subject
119
 
 
120
 
 
121
91
class Editor(MailClient):
122
92
    """DIY mail client that uses commit message editor"""
123
93