def _import_unixmailbox(self, author, db, mlid, msgfile_path): self.print_debug('import_mail') if not db: #db = self.env.get_db_cnx() handle_ta = True else: handle_ta = False printout(_("%(time)s Start Importing %(file_path)s ...", time=time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime()), file_path=msgfile_path)) fp = open(msgfile_path,"rb") mbox = mailbox.UnixMailbox(fp, self.msgfactory) counter =1 msg = mbox.next() while msg is not None: messageid = '' try: self.import_message(msg, author, mlid, db) except Exception, e: traceback.print_exc(e) exception_flag = True self.print_import_error(msg) if counter > 10000: break msg = mbox.next() counter = counter + 1
def do_help(self, line=None): arg = self.arg_tokenize(line) if arg[0]: try: doc = getattr(self, "_help_" + arg[0]) self.print_doc (doc) except AttributeError: printerr(_("No documentation found for '%(cmd)s'", cmd=arg[0])) else: printout(_("mailarc-admin - The Trac MailArchivePlugin Administration Console " "%(version)s", version=PLUGIN_VERSION)) if not self.interactive: print printout(_("Usage: mailarc-admin </path/to/projenv> " "[command [subcommand] [option ...]]\n") ) self.print_doc(self.all_docs())
def do_updatedb(self, line): db = self.db_open() self.env = self.env_open() from model import MailFinder mails = MailFinder.find_not_root(self.env) cursor = db.cursor() for mail in mails: root_id = mail.get_thread_root().messageid sql = "UPDATE mailarc SET threadroot = %s WHERE messageid = %s" printout(_('root_id=%s, messageid=%s' % (root_id, mail.messageid))) if root_id == mail.messageid: #自分が親(親メッセージIDのメールがDBに存在しない)場合、更新しない continue cursor.execute(sql, (root_id, mail.messageid)) self.print_info('%s' % sql) db.commit()
def _import_from_pop3(self, author, db, mlid): pop_server = self.env.config.get('mailarchive', 'pop3_server_' + mlid) if pop_server =='': pop_server = self.env.config.get('mailarchive', 'pop3_server') pop_user = self.env.config.get('mailarchive', 'pop3_user_' + mlid) if pop_user =='': pop_user = self.env.config.get('mailarchive', 'pop3_user') pop_password = self.env.config.get('mailarchive', 'pop3_password_' + mlid) if pop_password =='': pop_password = self.env.config.get('mailarchive', 'pop3_password') pop_delete = self.env.config.get('mailarchive', 'pop3_delete_' + mlid) if pop_delete =='': pop_delete = self.env.config.get('mailarchive', 'pop3_delete','none') #for POP SSL. Thanks! http://hidamarinonaka.jugem.cc/?eid=140 pop_ssl = self.env.config.get('mailarchive', 'pop3_ssl_' + mlid) if pop_ssl == '': pop_ssl = self.env.config.get('mailarchive', 'pop3_ssl' + mlid, 'no') if pop_server =='': printerr(_('trac.ini mailarchive pop3_server is null!')) elif pop_user == '': printerr(_('trac.ini mailarchive pop3_user is null!')) elif pop_password == '': printerr(_('trac.ini mailarchive pop3_password is null!')) printout(_("%(time)s Start Connction pop3 %(server)s:%(user)s ...", time=time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime()), server=pop_server, user=pop_user)) pop = None if pop_ssl == 'yes': printout(_('POP3_SSL access...')) pop = poplib.POP3_SSL(pop_server) elif pop_ssl == 'no': printout(_('POP3 access...')) pop = poplib.POP3(pop_server) else: printerr(_('trac.ini mailarchive pop3_ssl isn\'t yes/no!')) pop.user(pop_user) pop.pass_(pop_password) num_messages = len(pop.list()[1]) counter = 1 for i in range(num_messages): #lines = ['',] #for j in pop.retr(i+1)[1]: # lines.append(j + os.linesep) #mes_text = ''.join(lines) mes_text = ''.join(['%s\n' % line for line in pop.retr(i+1)[1]]) messageid = '' exception_flag = False msg = '' try: msg = email.message_from_string(mes_text) self.import_message(msg, author, mlid, db) except Exception, e: traceback.print_exc(e) exception_flag = True self.print_import_error(msg) # delete mail if pop_delete == 'all': pop.dele(i+1) printout(_(" Delete MailServer Message")) elif pop_delete == 'imported': if exception_flag == False: pop.dele(i+1) printout(_(" Delete MailServer Message")) else: pass if counter > 10000: break counter = counter + 1
def print_warning(self, line): printout("[Warning] %s" % line)
def print_error(self, line): printout("[Error] %s" % line)
def print_info(self, line): printout(line)
try: self.import_message(msg, author, mlid, db) except Exception, e: traceback.print_exc(e) exception_flag = True self.print_import_error(msg) if counter > 10000: break msg = mbox.next() counter = counter + 1 fp.close() #if handle_ta: db.commit() printout(_("End Imporing %(file_path)s. ", file_path=msgfile_path)) def _import_from_pop3(self, author, db, mlid): pop_server = self.env.config.get('mailarchive', 'pop3_server_' + mlid) if pop_server =='': pop_server = self.env.config.get('mailarchive', 'pop3_server') pop_user = self.env.config.get('mailarchive', 'pop3_user_' + mlid) if pop_user =='': pop_user = self.env.config.get('mailarchive', 'pop3_user') pop_password = self.env.config.get('mailarchive', 'pop3_password_' + mlid) if pop_password =='': pop_password = self.env.config.get('mailarchive', 'pop3_password')
write_tags(options.html, adjusted_fl, options.section) elif options.output_mode == 'minified' or options.output_mode == 'one-script': adjusted_of = os.path.relpath(options.output_file, options.html) util.write_tags(options.html, [adjusted_of], options.section) else: adjusted_fl = [os.path.relpath(f, os.getcwd()) for f in dep_list] if options.output_mode == 'list': if options.output_file: of = open(options.output_file, "w") for f in adjusted_fl: of.writeline(f) of.close() else: for f in dep_list: printout(os.path.relpath(f)) elif options.output_mode == 'tags': if options.output_file: of = open(options.output_file, "w") for f in adjusted_fl: of.writeline("<script type='text/javascript' src='%s'></script>" % f) of.close() else: for f in dep_list: printout("<script type='text/javascript' src='%s'></script>" % f) except JustError as e: printerr(str(e)) finally: if tfp: