- Timestamp:
- 01/04/11 11:27:44 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/email2trac.py.in
r498 r500 1761 1761 content_type = part.get_content_type() 1762 1762 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) 1765 1765 1766 1766 ## Check content type 1767 1767 # 1768 1768 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())) 1770 1770 continue 1771 1771 … … 1779 1779 # 1780 1780 if content_maintype == 'multipart': 1781 self.logger.debug(" Skipping multipart container")1781 self.logger.debug("\t Skipping multipart container") 1782 1782 continue 1783 1783 … … 1790 1790 if ALTERNATIVE_MULTIPART and self.parameters.drop_alternative_html_version: 1791 1791 if content_type == 'text/html': 1792 self.logger.debug(' Skipping alternative HTML message')1792 self.logger.debug('\t Skipping alternative HTML message') 1793 1793 ALTERNATIVE_MULTIPART = False 1794 1794 continue … … 1800 1800 1801 1801 if self.parameters.debug: 1802 s = ' 1802 s = '\t Filename: %s' % part.get_filename() 1803 1803 self.print_unicode(s) 1804 1804 … … 1813 1813 message_parts.append((filename, part)) 1814 1814 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 1821 1816 # 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 1831 1836 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 1836 1840 if self.parameters.dry_run: 1837 1841 print 'DRY_RUN: html2text conversion command: %s\n' %(cmd) … … 1846 1850 os.unlink(tmp_file) 1847 1851 1848 1849 1852 else: 1850 ## Save only as attachment. No further processing 1851 # 1853 self.logger.debug('\t No html2text conversion tool specified in email2trac.conf') 1852 1854 continue 1853 1855 1854 1855 1856 1857 1858 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') 1859 1861 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 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) 1891 1893 1892 1894 return message_parts
Note: See TracChangeset
for help on using the changeset viewer.