hi,

On 01/08/2015 07:33 PM, Antoine Beaupré wrote:
> On 2015-01-08 13:20:19, Muri Nicanor wrote:
>> however, i stumbled over another problem: thunderbird sets the
>> content-type for messages, so the mail then looks a bit confusing if i
>> just copy and paste the output...
>> if i find the time i'll think about a solution (maybe don't set content
>> type and just save two files, content and attachment...)
> 
> hmm... maybe changing what is saved then? maybe a non encoded version
> would be enough? just the signature
> output... ie. self.tmpkeyring.export_data(self.keyfpr)?

so, it now safes only the signature in the file, but i changed the email
on stdout from
msg.create_mail_from_block() to msg.body
if -o is set, then the signature is being written to the file, if not,
it is shown on stdout with the email body.
(i don't know if there is a usecase for having the MIME output printed
on the console...?)

muri
diff --git a/monkeysign/ui.py b/monkeysign/ui.py
index c9b6a30..c7c2219 100644
--- a/monkeysign/ui.py
+++ b/monkeysign/ui.py
@@ -93,6 +93,7 @@ class MonkeysignUi(object):
                           help=_('do not send email at all (default: use sendmail)'))
         parser.add_option('-t', '--to', dest='to', 
                           help=_('override destination email for testing (default: send individually encrypted email to each uid chosen)'))
+	parser.add_option('-o', '--output', dest='output', help=_('save the signature to a file'))
         return parser
 
     def parse_args(self, args):
@@ -380,7 +381,19 @@ expects an EmailFactory email, but will not mail if nomail is set"""
                 self.warn(_("""\
 not sending email to %s, as requested, here's the email message:
 
-%s""") % (msg.mailto, msg.create_mail_from_block()))
+%s""") % (msg.mailto, msg.body))
+            if self.options.output is not None:
+                if not os.path.exists(self.options.output):
+                    try:
+                        with open(self.options.output, 'w') as f:
+                            f.write(str(self.tmpkeyring.export_data(msg.keyfpr)))
+                            self.warn(_('Signature has been written to %s') % self.options.output)
+                    except IOError:
+                        self.warn(_('Could not write to file %s') % self.options.output)
+                else:
+                    self.warn(_('Could not write to %s: file exists') % self.options.output)
+            else:
+                self.warn(_('and here is the signature:\n%s') % str(self.tmpkeyring.export_data(msg.keyfpr)))
 
 
 class EmailFactory:

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to