Example #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))
Example #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))
Example #3
0
    def apply(self, ui):
        if not self.message:
            self.message = ui.current_buffer.get_selected_message()
        mail = self.message.get_email()
        # set body text
        name, address = self.message.get_author()
        timestamp = self.message.get_date()
        mailcontent = self.message.accumulate_body()
        envelope = Envelope(bodytext=mailcontent)

        # copy selected headers
        to_copy = ['Subject', 'From', 'To', 'Cc', 'Bcc', 'In-Reply-To',
                   'References']
        for key in to_copy:
            value = decode_header(mail.get(key, ''))
            if value:
                envelope.add(key, value)

        # copy attachments
        for b in self.message.get_attachments():
            envelope.attach(b)

        ui.apply_command(ComposeCommand(envelope=envelope))
Example #4
0
    def apply(self, ui):
        if not self.message:
            self.message = ui.current_buffer.get_selected_message()
        mail = self.message.get_email()
        # set body text
        name, address = self.message.get_author()
        timestamp = self.message.get_date()
        qf = settings.config.get_hook('reply_prefix')
        if qf:
            quotestring = qf(name, address, timestamp,
                             ui=ui, dbm=ui.dbman, aman=ui.accountman,
                             config=settings.config)
        else:
            quotestring = 'Quoting %s (%s)\n' % (name, timestamp)
        mailcontent = quotestring
        for line in self.message.accumulate_body().splitlines():
            mailcontent += '>' + line + '\n'

        envelope = Envelope(bodytext=mailcontent)

        # copy subject
        subject = decode_header(mail.get('Subject', ''))
        if not subject.startswith('Re:'):
            subject = 'Re: ' + subject
        envelope.add('Subject', subject)

        # set From
        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)

        # set To
        if self.groupreply:
            cleared = self.clear_my_address(my_addresses, mail.get('To', ''))
            if cleared:
                logging.info(mail['From'] + ', ' + cleared)
                to = mail['From'] + ', ' + cleared
                envelope.add('To', decode_header(to))

            else:
                envelope.add('To', decode_header(mail['From']))
            # copy cc and bcc for group-replies
            if 'Cc' in mail:
                cc = self.clear_my_address(my_addresses, mail['Cc'])
                envelope.add('Cc', decode_header(cc))
            if 'Bcc' in mail:
                bcc = self.clear_my_address(my_addresses, mail['Bcc'])
                envelope.add('Bcc', decode_header(bcc))
        else:
            envelope.add('To', decode_header(mail['From']))

        # set In-Reply-To header
        envelope.add('In-Reply-To', '<%s>' % self.message.get_message_id())

        # set References header
        old_references = mail.get('References', '')
        if old_references:
            old_references = old_references.split()
            references = old_references[-8:]
            if len(old_references) > 8:
                references = old_references[:1] + references
            references.append('<%s>' % self.message.get_message_id())
            envelope.add('References', ' '.join(references))
        else:
            envelope.add('References', '<%s>' % self.message.get_message_id())

        ui.apply_command(ComposeCommand(envelope=envelope))
Example #5
0
    def apply(self, ui):
        if not self.message:
            self.message = ui.current_buffer.get_selected_message()
        mail = self.message.get_email()
        # set body text
        name, address = self.message.get_author()
        timestamp = self.message.get_date()
        qf = settings.config.get_hook("reply_prefix")
        if qf:
            quotestring = qf(
                name, address, timestamp, ui=ui, dbm=ui.dbman, aman=ui.accountman, log=ui.logger, config=settings.config
            )
        else:
            quotestring = "Quoting %s (%s)\n" % (name, timestamp)
        mailcontent = quotestring
        for line in self.message.accumulate_body().splitlines():
            mailcontent += ">" + line + "\n"

        envelope = Envelope(bodytext=mailcontent)

        # copy subject
        subject = decode_header(mail.get("Subject", ""))
        if not subject.startswith("Re:"):
            subject = "Re: " + subject
        envelope.add("Subject", subject)

        # set From
        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)

        # set To
        if self.groupreply:
            cleared = self.clear_my_address(my_addresses, mail.get("To", ""))
            if cleared:
                logging.info(mail["From"] + ", " + cleared)
                to = mail["From"] + ", " + cleared
                envelope.add("To", decode_header(to))

            else:
                envelope.add("To", decode_header(mail["From"]))
            # copy cc and bcc for group-replies
            if "Cc" in mail:
                cc = self.clear_my_address(my_addresses, mail["Cc"])
                envelope.add("Cc", decode_header(cc))
            if "Bcc" in mail:
                bcc = self.clear_my_address(my_addresses, mail["Bcc"])
                envelope.add("Bcc", decode_header(bcc))
        else:
            envelope.add("To", decode_header(mail["From"]))

        # set In-Reply-To header
        envelope.add("In-Reply-To", "<%s>" % self.message.get_message_id())

        # set References header
        old_references = mail.get("References", "")
        if old_references:
            old_references = old_references.split()
            references = old_references[-8:]
            if len(old_references) > 8:
                references = old_references[:1] + references
            references.append("<%s>" % self.message.get_message_id())
            envelope.add("References", " ".join(references))
        else:
            envelope.add("References", "<%s>" % self.message.get_message_id())

        ui.apply_command(ComposeCommand(envelope=envelope))