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
=== modified file 'pqm/core.py'
--- pqm/core.py 2010-04-22 04:32:04 +0000
+++ pqm/core.py 2010-05-10 16:10:56 +0000
@@ -20,6 +20,7 @@
20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2121
22import os22import os
23from email import Message
23import smtplib24import smtplib
2425
25from pqm.errors import PQMCmdFailure, PQMException26from pqm.errors import PQMCmdFailure, PQMException
@@ -190,7 +191,9 @@
190191
191 def send_mail_reply(self, success, successes, unrecognized,192 def send_mail_reply(self, success, successes, unrecognized,
192 to_address, failedcmd, output, script):193 to_address, failedcmd, output, script):
194 message = Message()
193 if success:195 if success:
196 body_part = message
194 retmesg = mail_format_successes(197 retmesg = mail_format_successes(
195 successes, "Command was successful.", unrecognized)198 successes, "Command was successful.", unrecognized)
196 if len(successes) > 0:199 if len(successes) > 0:
@@ -198,19 +201,26 @@
198 else:201 else:
199 statusmsg='no valid commands given'202 statusmsg='no valid commands given'
200 else:203 else:
204 body_part = Message()
205 message['Content-type'] = 'multipart/mixed'
206
201 retmesg = mail_format_successes(207 retmesg = mail_format_successes(
202 successes, "Command passed checks, but was not committed.",208 successes, "Command passed checks, but was not committed.",
203 unrecognized)209 unrecognized)
204 retmesg += "\n%s" % failedcmd210 retmesg += "\n%s" % failedcmd
205 retmesg += '\nCommand failed!'211 retmesg += '\nCommand failed!'
206 retmesg += '\n' + script.format_output(output)212 attachment = Message()
213 attachment.set_payload(output)
214 attachment['Content-type'] = 'text/plain'
215 message.attach_part(attachment)
207 statusmsg='failure'216 statusmsg='failure'
217 body_part.set_payload(retmesg)
218 body_part['Content_type'] = 'text/plain'
219 message['From'] = self.nice_from_address
220 message['To'] = to_address
221 message['Subject'] = statusmsg
208 server = smtplib.SMTP(self.mail_server)222 server = smtplib.SMTP(self.mail_server)
209 server.sendmail(223 server.sendmail(self.from_address, [to_address], message.as_string())
210 self.from_address,
211 [to_address],
212 'From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s\n' % (
213 self.nice_from_address, to_address, statusmsg, retmesg))
214 server.quit()224 server.quit()
215225
216226

Subscribers

People subscribed via source and target branches