~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-08 21:26:50 UTC
  • mto: This revision was merged to the branch mainline in revision 4351.
  • Revision ID: aaron@aaronbentley.com-20090508212650-zxu1lnlpqogdsapk
Implement hook for bzr send.

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,
28
29
    msgeditor,
29
30
    osutils,
30
31
    urlutils,
34
35
mail_client_registry = registry.Registry()
35
36
 
36
37
 
 
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
 
37
49
class MailClient(object):
38
50
    """A mail client that can send messages with attachements."""
39
51
 
 
52
    hooks = MailClientHooks()
 
53
 
40
54
    def __init__(self, config):
41
55
        self.config = config
42
56
 
72
86
        :param basename: The name to use for the attachment, e.g.
73
87
            "send-nick-3252"
74
88
        """
 
89
        orig_body = body
75
90
        prompt = self._get_merge_prompt("Please describe these changes:", to,
76
91
                                        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)
77
96
        self.compose(prompt, to, subject, directive,
78
97
            'x-patch', '.patch', basename, body)
79
98
 
88
107
        return ''
89
108
 
90
109
 
 
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
 
91
121
class Editor(MailClient):
92
122
    """DIY mail client that uses commit message editor"""
93
123