| 1 | ごみです。 |
| 2 | {{{ |
| 3 | #!/usr/local/bin/python |
| 4 | # -*- coding: utf-8 -*- |
| 5 | |
| 6 | import sys |
| 7 | |
| 8 | import trac.scripts.admin |
| 9 | |
| 10 | |
| 11 | import cmd |
| 12 | import getpass |
| 13 | import os |
| 14 | import shlex |
| 15 | import shutil |
| 16 | import StringIO |
| 17 | import time |
| 18 | import traceback |
| 19 | import urllib |
| 20 | |
| 21 | import time |
| 22 | import calendar |
| 23 | import re |
| 24 | |
| 25 | import mimetypes |
| 26 | import email |
| 27 | #from email.Parser import Parser |
| 28 | from email.Header import decode_header |
| 29 | #from email.Utils import collapse_rfc2231_value |
| 30 | from email.Utils import decode_rfc2231 |
| 31 | import types |
| 32 | |
| 33 | import os |
| 34 | import email.Errors |
| 35 | import email.Utils |
| 36 | import mailbox |
| 37 | |
| 38 | from trac import util |
| 39 | from trac.wiki import wiki_to_html, IWikiSyntaxProvider |
| 40 | from trac.util import Markup |
| 41 | from trac.web.chrome import add_link, add_stylesheet, INavigationContributor, ITemplateProvider |
| 42 | from trac.attachment import attachments_to_hdf, Attachment |
| 43 | from trac.util import NaivePopen |
| 44 | import tempfile |
| 45 | |
| 46 | import getpass, poplib |
| 47 | |
| 48 | |
| 49 | try: |
| 50 | sum |
| 51 | except NameError: |
| 52 | def sum(list): |
| 53 | """Python2.2 doesn't have sum()""" |
| 54 | tot = 0 |
| 55 | for item in list: |
| 56 | tot += item |
| 57 | return tot |
| 58 | |
| 59 | |
| 60 | class MailArchiveAdmin(trac.scripts.admin.TracAdmin): |
| 61 | |
| 62 | __env = None |
| 63 | env = None |
| 64 | |
| 65 | |
| 66 | def msgfactory(self,fp): |
| 67 | try: |
| 68 | return email.message_from_file(fp) |
| 69 | except email.Errors.MessageParseError: |
| 70 | # Don't return None since that will |
| 71 | # stop the mailbox iterator |
| 72 | return '' |
| 73 | |
| 74 | def decode_to_unicode(self, basestr): |
| 75 | #RFC2231の添付ファイル名はget_filenameではunicodeTypeでくるみたいだ |
| 76 | if type(basestr) == types.UnicodeType : |
| 77 | return basestr |
| 78 | |
| 79 | decodefrag = email.Header.decode_header(basestr) |
| 80 | subj_fragments = ['',] |
| 81 | for frag, enc in decodefrag: |
| 82 | if enc: |
| 83 | frag = self.to_unicode(frag, enc) |
| 84 | subj_fragments.append(frag) |
| 85 | return ''.join(subj_fragments) |
| 86 | }}} |