# -*- coding: utf-8 -*-
import email
import imaplib
import re
from openerp import http
from email import header
class Advertisefor(http.Controller):
@http.route('/advertisefor/getemaillist/', type='http', csrf=False, auth='user')
def get_eamil_list_action(self, **kw):
query = []
recv_config = http.request.env['emailrecvconfig'].search_read(query,order='create_date desc')
# 取最新的配置
recv_config = recv_config[0]
email_address = recv_config['address']
email_password = recv_config['pwd']
imap_server_host = recv_config['imap_server']
imap_server_port = recv_config['server_port']
try:
email_server = imaplib.IMAP4_SSL(host=imap_server_host, port=imap_server_port)
print "imap4----connect server success, now will check username"
except:
print"imap4----sorry the given email server address connect time out"
exit(1)
try:
email_server.login(email_address,email_password)
print "imap4----username exist, now will check password"
except:
print"imap4----sorry the given email address or password seem do not correct"
exit(1)
email_server.select()
email_count = len(email_server.search(None, 'ALL')[1][0].split())
for e in reversed(range(1,email_count+1)):
typ, email_content = email_server.fetch('{}'.format(e).encode(), '