Exemplo n.º 1
0
    def apply(self, ui):
        if not self.message:
            self.message = ui.current_buffer.get_selected_message()
        mail = self.message.get_email()

        envelope = Envelope()
        if self.inline:  # inline mode
            # set body text
            name, address = self.message.get_author()
            timestamp = self.message.get_date()
            qf = settings.config.get_hook("forward_prefix")
            if qf:
                quote = qf(
                    name,
                    address,
                    timestamp,
                    ui=ui,
                    dbm=ui.dbman,
                    aman=ui.accountman,
                    log=ui.logger,
                    config=settings.config,
                )
            else:
                quote = "Forwarded message from %s (%s):\n" % (name, timestamp)
            mailcontent = quote
            for line in self.message.accumulate_body().splitlines():
                mailcontent += ">" + line + "\n"

            envelope.body = mailcontent

        else:  # attach original mode
            # attach original msg
            mail.set_default_type("message/rfc822")
            mail["Content-Disposition"] = "attachment"
            envelope.attachments.append(mail)

        # copy subject
        subject = decode_header(mail.get("Subject", ""))
        subject = "Fwd: " + subject
        envelope.add("Subject", subject)

        # set From
        # we look for own addresses in the To,Cc,Ccc headers in that order
        # and use the first match as new From header if there is one.
        my_addresses = ui.accountman.get_addresses()
        matched_address = ""
        in_to = [a for a in my_addresses if a in mail.get("To", "")]
        if in_to:
            matched_address = in_to[0]
        else:
            cc = mail.get("Cc", "") + mail.get("Bcc", "")
            in_cc = [a for a in my_addresses if a in cc]
            if in_cc:
                matched_address = in_cc[0]
        if matched_address:
            account = ui.accountman.get_account_by_address(matched_address)
            fromstring = "%s <%s>" % (account.realname, account.address)
            envelope.add("From", fromstring)
        ui.apply_command(ComposeCommand(envelope=envelope))
Exemplo n.º 2
0
    def apply(self, ui):
        if not self.message:
            self.message = ui.current_buffer.get_selected_message()
        mail = self.message.get_email()

        envelope = Envelope()
        if self.inline:  # inline mode
            # set body text
            name, address = self.message.get_author()
            timestamp = self.message.get_date()
            qf = settings.config.get_hook('forward_prefix')
            if qf:
                quote = qf(name, address, timestamp,
                             ui=ui, dbm=ui.dbman, aman=ui.accountman,
                             config=settings.config)
            else:
                quote = 'Forwarded message from %s (%s):\n' % (name, timestamp)
            mailcontent = quote
            for line in self.message.accumulate_body().splitlines():
                mailcontent += '>' + line + '\n'

            envelope.body = mailcontent

        else:  # attach original mode
            # attach original msg
            mail.set_default_type('message/rfc822')
            mail['Content-Disposition'] = 'attachment'
            envelope.attachments.append(mail)

        # copy subject
        subject = decode_header(mail.get('Subject', ''))
        subject = 'Fwd: ' + subject
        envelope.add('Subject', subject)

        # set From
        # we look for own addresses in the To,Cc,Ccc headers in that order
        # and use the first match as new From header if there is one.
        my_addresses = ui.accountman.get_addresses()
        matched_address = ''
        in_to = [a for a in my_addresses if a in mail.get('To', '')]
        if in_to:
            matched_address = in_to[0]
        else:
            cc = mail.get('Cc', '') + mail.get('Bcc', '')
            in_cc = [a for a in my_addresses if a in cc]
            if in_cc:
                matched_address = in_cc[0]
        if matched_address:
            account = ui.accountman.get_account_by_address(matched_address)
            fromstring = '%s <%s>' % (account.realname, account.address)
            envelope.add('From', fromstring)
        ui.apply_command(ComposeCommand(envelope=envelope))