Changeset 500 for trunk


Ignore:
Timestamp:
01/04/11 11:27:44 (13 years ago)
Author:
bas
Message:

fixed a bug when sending html and text messages. we did get empty tickets :-(

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/email2trac.py.in

    r498 r500  
    17611761                        content_type =  part.get_content_type()
    17621762
    1763                         self.logger.debug('Message part: Main-Type: %s' % content_maintype)
    1764                         self.logger.debug('Message part: Content-Type: %s' % content_type)
     1763                        self.logger.debug('\t Message part: Main-Type: %s' % content_maintype)
     1764                        self.logger.debug('\t Message part: Content-Type: %s' % content_type)
    17651765
    17661766                        ## Check content type
    17671767                        #
    17681768                        if content_type in self.STRIP_CONTENT_TYPES:
    1769                                 self.logger.debug("A %s attachment named '%s' was skipped" %(content_type, part.get_filename()))
     1769                                self.logger.debug("\t A %s attachment named '%s' was skipped" %(content_type, part.get_filename()))
    17701770                                continue
    17711771
     
    17791779                        #
    17801780                        if content_maintype == 'multipart':
    1781                                 self.logger.debug("Skipping multipart container")
     1781                                self.logger.debug("\t Skipping multipart container")
    17821782                                continue
    17831783                       
     
    17901790                        if ALTERNATIVE_MULTIPART and self.parameters.drop_alternative_html_version:
    17911791                                if content_type == 'text/html':
    1792                                         self.logger.debug('Skipping alternative HTML message')
     1792                                        self.logger.debug('\t Skipping alternative HTML message')
    17931793                                        ALTERNATIVE_MULTIPART = False
    17941794                                        continue
     
    18001800
    18011801                                if self.parameters.debug:
    1802                                         s = '              Filename: %s' % part.get_filename()
     1802                                        s = '\t Filename: %s' % part.get_filename()
    18031803                                        self.print_unicode(s)
    18041804
     
    18131813                                message_parts.append((filename, part))
    18141814
    1815                         ## Inline text parts are where the body is
    1816                         #
    1817                         if (content_type in ['text/plain', 'text/html']) and inline:
    1818                                 self.logger.debug('               Inline body part (content_type = %s)' %(content_type))
    1819 
    1820                                 ## Try to decode, if fails then do not decode
     1815                                ## We van only convert html messages
    18211816                                #
    1822                                 body_text = part.get_payload(decode=1)
    1823                                 if not body_text:                       
    1824                                         body_text = part.get_payload(decode=0)
    1825 
    1826                                 #print type(body_text) must be string
    1827 
    1828                                 ## Convert html message to text if a conversion command is specified
    1829                                 #
    1830                                 if content_type == 'text/html' and self.parameters.html2text_cmd:
     1817                                if not content_type == 'text/html':
     1818                                        self.logger.debug('\t Appending content_type = %s' %(content_type))
     1819                                        continue
     1820
     1821                        if not inline:
     1822                                        self.logger.debug('\t Skipping %s, not an inline messsage part' %(content_type))
     1823                                        continue
     1824                               
     1825                        ## Try to decode message part. We have a html or plain text messafe
     1826                        #
     1827                        body_text = part.get_payload(decode=1)
     1828                        if not body_text:                       
     1829                                body_text = part.get_payload(decode=0)
     1830
     1831                        ## Try to convert html message
     1832                        #
     1833                        if content_type == 'text/html':
     1834                                if self.parameters.html2text_cmd:
     1835
    18311836                                        tmp_file = tempfile.mktemp('.email2trac')
    1832                                         cmd = '%s %s' %(self.parameters.html2text_cmd, tmp_file)
    1833 
    1834                                         self.logger.debug('html2text conversion %s'%(cmd))
    1835 
     1837                                        cmd = '%s %s' %(self.parameters.html2text_cmd, tmp_file)
     1838                                        self.logger.debug('\t html2text conversion %s'%(cmd))
     1839                                       
    18361840                                        if self.parameters.dry_run:
    18371841                                                print 'DRY_RUN: html2text conversion command: %s\n' %(cmd)
     
    18461850                                                os.unlink(tmp_file)
    18471851
    1848 
    18491852                                else:
    1850                                         ## Save only as attachment. No further processing
    1851                                         #
     1853                                        self.logger.debug('\t No html2text conversion tool specified in email2trac.conf')
    18521854                                        continue
    18531855
    1854                                 format = email.Utils.collapse_rfc2231_value(part.get_param('Format', 'fixed')).lower()
    1855                                 delsp = email.Utils.collapse_rfc2231_value(part.get_param('DelSp', 'no')).lower()
    1856 
    1857                                 if self.parameters.reflow and not self.parameters.verbatim_format and format == 'flowed':
    1858                                         body_text = self.reflow(body_text, delsp == 'yes')
     1856                        format = email.Utils.collapse_rfc2231_value(part.get_param('Format', 'fixed')).lower()
     1857                        delsp = email.Utils.collapse_rfc2231_value(part.get_param('DelSp', 'no')).lower()
     1858
     1859                        if self.parameters.reflow and not self.parameters.verbatim_format and format == 'flowed':
     1860                                body_text = self.reflow(body_text, delsp == 'yes')
    18591861       
    1860                                 if self.parameters.strip_signature:
    1861                                         body_text = self.strip_signature(body_text)
    1862 
    1863                                 if self.parameters.strip_quotes:
    1864                                         body_text = self.strip_quotes(body_text)
    1865 
    1866                                 if self.parameters.inline_properties:
    1867                                         body_text = self.inline_properties(body_text)
    1868 
    1869                                 if self.parameters.use_textwrap:
    1870                                         body_text = self.wrap_text(body_text)
    1871 
    1872                                 ## Get contents charset (iso-8859-15 if not defined in mail headers)
    1873                                 #
    1874                                 charset = part.get_content_charset()
    1875                                 if not charset:
    1876                                         charset = 'iso-8859-15'
    1877 
    1878                                 try:
    1879                                         ubody_text = unicode(body_text, charset)
    1880 
    1881                                 except UnicodeError, detail:
    1882                                         ubody_text = unicode(body_text, 'iso-8859-15')
    1883 
    1884                                 except LookupError, detail:
    1885                                         ubody_text = 'ERROR: Could not find charset: %s, please install' %(charset)
    1886 
    1887                                 if self.parameters.verbatim_format:
    1888                                         message_parts.append('{{{\r\n%s\r\n}}}' %ubody_text)
    1889                                 else:
    1890                                         message_parts.append('%s' %ubody_text)
     1862                        if self.parameters.strip_signature:
     1863                                body_text = self.strip_signature(body_text)
     1864
     1865                        if self.parameters.strip_quotes:
     1866                                body_text = self.strip_quotes(body_text)
     1867
     1868                        if self.parameters.inline_properties:
     1869                                body_text = self.inline_properties(body_text)
     1870
     1871                        if self.parameters.use_textwrap:
     1872                                body_text = self.wrap_text(body_text)
     1873
     1874                        ## Get contents charset (iso-8859-15 if not defined in mail headers)
     1875                        #
     1876                        charset = part.get_content_charset()
     1877                        if not charset:
     1878                                charset = 'iso-8859-15'
     1879
     1880                        try:
     1881                                ubody_text = unicode(body_text, charset)
     1882
     1883                        except UnicodeError, detail:
     1884                                ubody_text = unicode(body_text, 'iso-8859-15')
     1885
     1886                        except LookupError, detail:
     1887                                ubody_text = 'ERROR: Could not find charset: %s, please install' %(charset)
     1888
     1889                        if self.parameters.verbatim_format:
     1890                                message_parts.append('{{{\r\n%s\r\n}}}' %ubody_text)
     1891                        else:
     1892                                message_parts.append('%s' %ubody_text)
    18911893
    18921894                return message_parts
Note: See TracChangeset for help on using the changeset viewer.