PQM

Merge lp:~abentley/pqm/attachment into lp:pqm

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 235
Proposed branch: lp:~abentley/pqm/attachment
Merge into: lp:pqm
Diff against target: 52 lines (+16/-6)
1 file modified
pqm/core.py (+16/-6)
To merge this branch: bzr merge lp:~abentley/pqm/attachment
Reviewer Review Type Date Requested Status
pqm developers Pending
Review via email: mp+25009@code.launchpad.net

Description of the change

Add support for attachments.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pqm/core.py'
2--- pqm/core.py 2010-04-22 04:32:04 +0000
3+++ pqm/core.py 2010-05-10 16:10:56 +0000
4@@ -20,6 +20,7 @@
5 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6
7 import os
8+from email import Message
9 import smtplib
10
11 from pqm.errors import PQMCmdFailure, PQMException
12@@ -190,7 +191,9 @@
13
14 def send_mail_reply(self, success, successes, unrecognized,
15 to_address, failedcmd, output, script):
16+ message = Message()
17 if success:
18+ body_part = message
19 retmesg = mail_format_successes(
20 successes, "Command was successful.", unrecognized)
21 if len(successes) > 0:
22@@ -198,19 +201,26 @@
23 else:
24 statusmsg='no valid commands given'
25 else:
26+ body_part = Message()
27+ message['Content-type'] = 'multipart/mixed'
28+
29 retmesg = mail_format_successes(
30 successes, "Command passed checks, but was not committed.",
31 unrecognized)
32 retmesg += "\n%s" % failedcmd
33 retmesg += '\nCommand failed!'
34- retmesg += '\n' + script.format_output(output)
35+ attachment = Message()
36+ attachment.set_payload(output)
37+ attachment['Content-type'] = 'text/plain'
38+ message.attach_part(attachment)
39 statusmsg='failure'
40+ body_part.set_payload(retmesg)
41+ body_part['Content_type'] = 'text/plain'
42+ message['From'] = self.nice_from_address
43+ message['To'] = to_address
44+ message['Subject'] = statusmsg
45 server = smtplib.SMTP(self.mail_server)
46- server.sendmail(
47- self.from_address,
48- [to_address],
49- 'From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s\n' % (
50- self.nice_from_address, to_address, statusmsg, retmesg))
51+ server.sendmail(self.from_address, [to_address], message.as_string())
52 server.quit()
53
54

Subscribers

People subscribed via source and target branches