# Author: Zhang Huangbin import sys import web from controllers import base from libs.mailparser import parseRawMessage from libs.amavisd import log as loglib, quarantine cfg = web.iredconfig session = web.config.get('_session') class InOutMails: @base.require_login def GET(self, logType='sent', cur_page=1): self.logType = str(logType) # Get current page. self.cur_page = web.safestr(cur_page) if not self.cur_page.isdigit() or self.cur_page == '0': self.cur_page = 1 else: self.cur_page = int(self.cur_page) logLib = loglib.Log() (total, records, mailIds) = logLib.getInOutMails(logType=self.logType, cur_page=self.cur_page,) return web.render( 'amavisd/inout.html', logType=self.logType, cur_page=self.cur_page, total=total, records=records, msg=web.input().get('msg'), ) @base.require_login def POST(self, logType='sent', cur_page=1): self.logType = str(logType) # Get current page. self.cur_page = str(cur_page) if not self.cur_page.isdigit() or self.cur_page == '0': self.cur_page = 1 else: self.cur_page = int(self.cur_page) i = web.input(mailid=[], _unicode=False,) mailIds = i.get('mailid', []) logLib = loglib.Log() result = logLib.deleteRecordsByMailID(logType=self.logType, id=mailIds,) if result[0] is True: return web.seeother('/system/maillog/%s/page/%d?msg=DELETED' % (self.logType, self.cur_page,)) else: return web.seeother('/system/maillog/%s/page/%d?msg=%s' % (self.logType, self.cur_page, str(result[1]),)) class QuarantinedMails: @base.require_login def GET(self, cur_page=1): i = web.input() # Get current page. self.cur_page = web.safestr(cur_page) if not self.cur_page.isdigit() or self.cur_page == '0': self.cur_page = 1 else: self.cur_page = int(self.cur_page) quarantineLib = quarantine.Quarantine() (total, records) = quarantineLib.getRecordsOfQuarantinedMails(cur_page=self.cur_page) return web.render( 'amavisd/quarantined.html', cur_page=self.cur_page, total=total, records=records, msg=i.get('msg'), ) @base.require_login def POST(self, cur_page=1): i = web.input(record=[], _unicode=False) self.action = i.get('action', None) # Get current page. self.cur_page = web.safestr(cur_page) if not self.cur_page.isdigit() or self.cur_page == '0': self.cur_page = 1 else: self.cur_page = int(self.cur_page) # Get necessary information from web form. records = [] mailids = [] msg = i.get('msg') for r in i.get('record', []): tmp = r.split('\\r\\n') # escape '\r\n' if len(tmp) == 2: records += [{'mail_id': tmp[0], 'secret_id': tmp[1]}] mailids += [tmp[0]] if self.action == 'release': quarantineLib = quarantine.Quarantine() result = quarantineLib.releaseQuarantinedMails(records=records) msg = 'RELEASED' elif self.action == 'delete': logLib = loglib.Log() result = logLib.deleteRecordsByMailID(logType='quarantine', id=mailids) msg = 'DELETED' else: result = (False, 'INVALID_ACTION') if result[0] is True: web.seeother('/system/maillog/quarantined?msg=%s' % msg) else: web.seeother('/system/maillog/quarantined?msg=%s' % (result[1])) class GetRawMessageOfQuarantinedMail: @base.require_login def GET(self, mail_id): quarantineLib = quarantine.Quarantine() result = quarantineLib.getRawMessage(mail_id) if result[0] is True: # Parse mail and convert to HTML. headers, body, attachments = parseRawMessage(result[1]) return web.render( 'amavisd/quarantined_raw.html', mail_id=mail_id, headers=headers, body=body, attachments=attachments, ) else: return web.seeother('/system/maillog/quarantined?msg=%s' % result[1])