/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/mail_client.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-16 23:19:12 UTC
  • mfrom: (7180 work)
  • mto: This revision was merged to the branch mainline in revision 7294.
  • Revision ID: jelmer@jelmer.uk-20181116231912-e043vpq22bdkxa6q
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
        prompt = self._get_merge_prompt("Please describe these changes:", to,
104
104
                                        subject, directive)
105
105
        self.compose(prompt, to, subject, directive,
106
 
            'x-patch', '.patch', basename, body)
 
106
                     'x-patch', '.patch', basename, body)
107
107
 
108
108
    def _get_merge_prompt(self, prompt, to, subject, attachment):
109
109
        """Generate a prompt string.  Overridden by Editor.
144
144
                                        body,
145
145
                                        attachment,
146
146
                                        attachment_mime_subtype=mime_subtype)
 
147
 
 
148
 
147
149
mail_client_registry.register('editor', Editor,
148
150
                              help=Editor.__doc__)
149
151
 
280
282
        options_list = ['%s=%s' % (k, urlutils.escape(v)) for (k, v) in
281
283
                        sorted(message_options.items())]
282
284
        return ['mailto:%s?%s' % (self._encode_safe(to or ''),
283
 
            '&'.join(options_list))]
 
285
                                  '&'.join(options_list))]
 
286
 
 
287
 
284
288
mail_client_registry.register('evolution', Evolution,
285
289
                              help=Evolution.__doc__)
286
290
 
294
298
        """See ExternalMailClient._get_compose_commandline"""
295
299
        message_options = []
296
300
        if subject is not None:
297
 
            message_options.extend(['-s', self._encode_safe(subject)])
 
301
            message_options.extend(
 
302
                ['-s', self._encode_safe(subject)])
298
303
        if attach_path is not None:
299
 
            message_options.extend(['-a',
300
 
                self._encode_path(attach_path, 'attachment')])
 
304
            message_options.extend(
 
305
                ['-a', self._encode_path(attach_path, 'attachment')])
301
306
        if body is not None:
302
307
            # Store the temp file object in self, so that it does not get
303
308
            # garbage collected and delete the file before mutt can read it.
309
314
        if to is not None:
310
315
            message_options.extend(['--', self._encode_safe(to)])
311
316
        return message_options
 
317
 
 
318
 
312
319
mail_client_registry.register('mutt', Mutt,
313
320
                              help=Mutt.__doc__)
314
321
 
323
330
    send attachments.
324
331
    """
325
332
 
326
 
    _client_commands = ['thunderbird', 'mozilla-thunderbird', 'icedove',
 
333
    _client_commands = [
 
334
        'thunderbird', 'mozilla-thunderbird', 'icedove',
327
335
        '/Applications/Mozilla/Thunderbird.app/Contents/MacOS/thunderbird-bin',
328
336
        '/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin']
329
337
 
338
346
            message_options['attachment'] = urlutils.local_path_to_url(
339
347
                attach_path)
340
348
        if body is not None:
341
 
            options_list = ['body=%s' % urlutils.quote(self._encode_safe(body))]
 
349
            options_list = ['body=%s' %
 
350
                            urlutils.quote(self._encode_safe(body))]
342
351
        else:
343
352
            options_list = []
344
353
        options_list.extend(["%s='%s'" % (k, v) for k, v in
345
 
                        sorted(message_options.items())])
 
354
                             sorted(message_options.items())])
346
355
        return ['-compose', ','.join(options_list)]
 
356
 
 
357
 
347
358
mail_client_registry.register('thunderbird', Thunderbird,
348
359
                              help=Thunderbird.__doc__)
349
360
 
359
370
        if subject is not None:
360
371
            message_options.extend(['-s', self._encode_safe(subject)])
361
372
        if attach_path is not None:
362
 
            message_options.extend(['--attach',
363
 
                self._encode_path(attach_path, 'attachment')])
 
373
            message_options.extend(
 
374
                ['--attach', self._encode_path(attach_path, 'attachment')])
364
375
        if to is not None:
365
376
            message_options.extend([self._encode_safe(to)])
366
377
        return message_options
 
378
 
 
379
 
367
380
mail_client_registry.register('kmail', KMail,
368
381
                              help=KMail.__doc__)
369
382
 
415
428
 
416
429
 
417
430
class XDGEmail(BodyExternalMailClient):
418
 
    __doc__ = """xdg-email attempts to invoke the user's preferred mail client"""
 
431
    __doc__ = """xdg-email attempts to invoke the preferred mail client"""
419
432
 
420
433
    _client_commands = ['xdg-email']
421
434
 
428
441
            commandline.extend(['--subject', self._encode_safe(subject)])
429
442
        if attach_path is not None:
430
443
            commandline.extend(['--attach',
431
 
                self._encode_path(attach_path, 'attachment')])
 
444
                                self._encode_path(attach_path, 'attachment')])
432
445
        if body is not None:
433
446
            commandline.extend(['--body', self._encode_safe(body)])
434
447
        return commandline
 
448
 
 
449
 
435
450
mail_client_registry.register('xdg-email', XDGEmail,
436
451
                              help=XDGEmail.__doc__)
437
452
 
506
521
        try:
507
522
            os.write(fd, _defun)
508
523
        finally:
509
 
            os.close(fd) # Just close the handle but do not remove the file.
 
524
            os.close(fd)  # Just close the handle but do not remove the file.
510
525
        return temp_file
511
526
 
512
527
    def _get_compose_commandline(self, to, subject, attach_path):
534
549
            elisp = self._prepare_send_function()
535
550
            self.elisp_tmp_file = elisp
536
551
            lmmform = '(load "%s")' % elisp
537
 
            mmform  = '(bzr-add-mime-att "%s")' % \
 
552
            mmform = '(bzr-add-mime-att "%s")' % \
538
553
                self._encode_path(attach_path, 'attachment')
539
554
            rmform = '(delete-file "%s")' % elisp
540
555
            commandline.append(lmmform)
542
557
            commandline.append(rmform)
543
558
 
544
559
        return commandline
 
560
 
 
561
 
545
562
mail_client_registry.register('emacsclient', EmacsMail,
546
563
                              help=EmacsMail.__doc__)
547
564
 
562
579
        except simplemapi.MAPIError as e:
563
580
            if e.code != simplemapi.MAPI_USER_ABORT:
564
581
                raise MailClientNotFound(['MAPI supported mail client'
565
 
                                                 ' (error %d)' % (e.code,)])
 
582
                                          ' (error %d)' % (e.code,)])
 
583
 
 
584
 
566
585
mail_client_registry.register('mapi', MAPIClient,
567
586
                              help=MAPIClient.__doc__)
568
587
 
580
599
    _client_commands = ['osascript']
581
600
 
582
601
    def _get_compose_commandline(self, to, subject, attach_path, body=None,
583
 
                                from_=None):
584
 
       """See ExternalMailClient._get_compose_commandline"""
585
 
 
586
 
       fd, self.temp_file = tempfile.mkstemp(prefix="bzr-send-",
587
 
                                         suffix=".scpt")
588
 
       try:
589
 
           os.write(fd, 'tell application "Mail"\n')
590
 
           os.write(fd, 'set newMessage to make new outgoing message\n')
591
 
           os.write(fd, 'tell newMessage\n')
592
 
           if to is not None:
593
 
               os.write(fd, 'make new to recipient with properties'
594
 
                   ' {address:"%s"}\n' % to)
595
 
           if from_ is not None:
596
 
               # though from_ doesn't actually seem to be used
597
 
               os.write(fd, 'set sender to "%s"\n'
598
 
                   % sender.replace('"', '\\"'))
599
 
           if subject is not None:
600
 
               os.write(fd, 'set subject to "%s"\n'
601
 
                   % subject.replace('"', '\\"'))
602
 
           if body is not None:
603
 
               # FIXME: would be nice to prepend the body to the
604
 
               # existing content (e.g., preserve signature), but
605
 
               # can't seem to figure out the right applescript
606
 
               # incantation.
607
 
               os.write(fd, 'set content to "%s\\n\n"\n' %
608
 
                   body.replace('"', '\\"').replace('\n', '\\n'))
609
 
 
610
 
           if attach_path is not None:
611
 
               # FIXME: would be nice to first append a newline to
612
 
               # ensure the attachment is on a new paragraph, but
613
 
               # can't seem to figure out the right applescript
614
 
               # incantation.
615
 
               os.write(fd, 'tell content to make new attachment'
616
 
                   ' with properties {file name:"%s"}'
617
 
                   ' at after the last paragraph\n'
618
 
                   % self._encode_path(attach_path, 'attachment'))
619
 
           os.write(fd, 'set visible to true\n')
620
 
           os.write(fd, 'end tell\n')
621
 
           os.write(fd, 'end tell\n')
622
 
       finally:
623
 
           os.close(fd) # Just close the handle but do not remove the file.
624
 
       return [self.temp_file]
 
602
                                 from_=None):
 
603
        """See ExternalMailClient._get_compose_commandline"""
 
604
 
 
605
        fd, self.temp_file = tempfile.mkstemp(prefix="bzr-send-",
 
606
                                              suffix=".scpt")
 
607
        try:
 
608
            os.write(fd, 'tell application "Mail"\n')
 
609
            os.write(fd, 'set newMessage to make new outgoing message\n')
 
610
            os.write(fd, 'tell newMessage\n')
 
611
            if to is not None:
 
612
                os.write(fd, 'make new to recipient with properties'
 
613
                         ' {address:"%s"}\n' % to)
 
614
            if from_ is not None:
 
615
                # though from_ doesn't actually seem to be used
 
616
                os.write(fd, 'set sender to "%s"\n'
 
617
                         % from_.replace('"', '\\"'))
 
618
            if subject is not None:
 
619
                os.write(fd, 'set subject to "%s"\n'
 
620
                         % subject.replace('"', '\\"'))
 
621
            if body is not None:
 
622
                # FIXME: would be nice to prepend the body to the
 
623
                # existing content (e.g., preserve signature), but
 
624
                # can't seem to figure out the right applescript
 
625
                # incantation.
 
626
                os.write(fd, 'set content to "%s\\n\n"\n' %
 
627
                         body.replace('"', '\\"').replace('\n', '\\n'))
 
628
 
 
629
            if attach_path is not None:
 
630
                # FIXME: would be nice to first append a newline to
 
631
                # ensure the attachment is on a new paragraph, but
 
632
                # can't seem to figure out the right applescript
 
633
                # incantation.
 
634
                os.write(fd, 'tell content to make new attachment'
 
635
                         ' with properties {file name:"%s"}'
 
636
                         ' at after the last paragraph\n'
 
637
                         % self._encode_path(attach_path, 'attachment'))
 
638
            os.write(fd, 'set visible to true\n')
 
639
            os.write(fd, 'end tell\n')
 
640
            os.write(fd, 'end tell\n')
 
641
        finally:
 
642
            os.close(fd)  # Just close the handle but do not remove the file.
 
643
        return [self.temp_file]
 
644
 
 
645
 
625
646
mail_client_registry.register('mail.app', MailApp,
626
647
                              help=MailApp.__doc__)
627
648
 
647
668
                                               attachment, mime_subtype,
648
669
                                               extension, basename, body)
649
670
        except MailClientNotFound:
650
 
            return Editor(self.config).compose(prompt, to, subject,
651
 
                          attachment, mime_subtype, extension, body)
 
671
            return Editor(self.config).compose(
 
672
                prompt, to, subject, attachment, mime_subtype, extension, body)
652
673
 
653
674
    def compose_merge_request(self, to, subject, directive, basename=None,
654
675
                              body=None):
655
676
        """See MailClient.compose_merge_request"""
656
677
        try:
657
 
            return self._mail_client().compose_merge_request(to, subject,
658
 
                    directive, basename=basename, body=body)
 
678
            return self._mail_client().compose_merge_request(
 
679
                to, subject, directive, basename=basename, body=body)
659
680
        except MailClientNotFound:
660
 
            return Editor(self.config).compose_merge_request(to, subject,
661
 
                          directive, basename=basename, body=body)
 
681
            return Editor(self.config).compose_merge_request(
 
682
                to, subject, directive, basename=basename, body=body)
 
683
 
 
684
 
662
685
mail_client_registry.register(u'default', DefaultMail,
663
686
                              help=DefaultMail.__doc__)
664
687
mail_client_registry.default_key = u'default'
665
688
 
666
 
opt_mail_client = _mod_config.RegistryOption('mail_client',
667
 
        mail_client_registry, help='E-mail client to use.', invalid='error')
 
689
opt_mail_client = _mod_config.RegistryOption(
 
690
    'mail_client', mail_client_registry, help='E-mail client to use.',
 
691
    invalid='error')