Changeset 231


Ignore:
Timestamp:
10/31/08 18:08:56 (15 years ago)
Author:
bas
Message:

email2trac.py.in:

ChangeLog?

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r228 r231  
     1200X-XX-XX
     2  * applied patch to support RFC 3676 (format=flowed), closed #94
     3    This patch adds a new option: reflow (default: False/0)
     4    Author: ben at fetchsoftworks dot com
     5    Applied by : Bas van der Vlies
     6
     7  * Fixed a bug in reply_all option, closes #95
     8    Reported by: gmcgrath at princeton dot edu
     9    Fixed by: Bas van der Vlies
     10
    1112008-10-13
    212  * Fixed a bug in email_header formating. When an email2trac ticket
     
    3444  * added recipient_list parameter.  If set then only mail is accepted if
    3545    to-field matches. This only uses when people use a drop box to accept
    36     emai for several email addresses, (closes #77)
     46    email for several email addresses, (closes #77)
    3747    Author: Bas van der Vlies, jon dot wbstr at gmail dot com
    3848
  • trunk/email2trac.py.in

    r230 r231  
    219219                        self.VERBATIM_FORMAT = 1
    220220
     221                if parameters.has_key('reflow'):
     222                        self.REFLOW = int(parameter['reflow'])
     223                else:
     224                        self.REFLOW = 1
     225
    221226                if parameters.has_key('strip_signature'):
    222227                        self.STRIP_SIGNATURE = int(parameters['strip_signature'])
     
    860865                return ('\n'.join(body))
    861866
     867        def reflow(self, text, delsp = 0):
     868                """
     869                Reflow the message based on the format="flowed" specification (RFC 3676)
     870                """
     871                flowedlines = []
     872                quotelevel = 0
     873                prevflowed = 0
     874
     875                for line in text.splitlines():
     876                        from re import match
     877                       
     878                        # Figure out the quote level and the content of the current line
     879                        m = match('(>*)( ?)(.*)', line)
     880                        linequotelevel = len(m.group(1))
     881                        line = m.group(3)
     882
     883                        # Determine whether this line is flowed
     884                        if line and line != '-- ' and line[-1] == ' ':
     885                                flowed = 1
     886                        else:
     887                                flowed = 0
     888
     889                        if flowed and delsp and line and line[-1] == ' ':
     890                                line = line[:-1]
     891
     892                        # If the previous line is flowed, append this line to it
     893                        if prevflowed and line != '-- ' and linequotelevel == quotelevel:
     894                                flowedlines[-1] += line
     895                        # Otherwise, start a new line
     896                        else:
     897                                flowedlines.append('>' * linequotelevel + line)
     898
     899                        prevflowed = flowed
     900                       
     901
     902                return '\n'.join(flowedlines)
     903
    862904        def strip_quotes(self, text):
    863905                """
     
    918960                                if not body_text:                       
    919961                                        body_text = part.get_payload(decode=0)
     962
     963                                format = email.Utils.collapse_rfc2231_value(part.get_param('Format')).lower()
     964                                delsp = email.Utils.collapse_rfc2231_value(part.get_param('DelSp')).lower()
     965
     966                                if self.REFLOW and not self.VERBATIM_FORMAT and format == 'flowed':
     967                                        body_text = self.reflow(body_text, delsp == 'yes')
    920968       
    921969                                if self.STRIP_SIGNATURE:
Note: See TracChangeset for help on using the changeset viewer.