[IMP]: improvements in fetchmail and document email

bzr revid: mga@tinyerp.com-20100426052001-zv1mtvguufzz7ob0
This commit is contained in:
Mantavya Gajjar 2010-04-26 10:50:01 +05:30
parent 08f80fef82
commit a02f0877a7
4 changed files with 21 additions and 11 deletions

View File

@ -79,7 +79,7 @@ class email_to_document(osv.osv):
if file_ext[1] not in ext:
logger.notifyChannel('document', netsvc.LOG_WARNING, 'file type %s is not allows to process for directory %s' % (file_ext[1], dr.directory_id.name))
continue
data_attach = {
'name': attactment,
'datas':binascii.b2a_base64(str(attachents.get(attactment))),

View File

@ -93,11 +93,11 @@
<field name="domain">[]</field>
</record>
<menuitem
parent="base.menu_document"
id="menu_action_document_email_tree"
name="Email to Documents"
action="action_document_email_form"/>
<!-- <menuitem -->
<!-- parent="base.menu_document"-->
<!-- id="menu_action_document_email_tree" -->
<!-- name="Email to Documents"-->
<!-- action="action_document_email_form"/>-->
</data>
</openerp>

View File

@ -320,12 +320,22 @@ class email_server(osv.osv):
return res_id
def __fetch_mail(self, cr, uid, ids, context={}):
sendmail_thread = threading.Thread(target=self.fetch_mail, args=(cr, uid, ids))
sendmail_thread.start()
return True
def _fetch_mails(self, cr, uid, ids=False, context={}):
if not ids:
ids = self.search(cr, uid, [])
return self.fetch_mail(cr, uid, ids, context)
def fetch_mail(self, cr, uid, ids, context={}):
fp = os.popen('ping www.google.com -c 1 -w 5',"r")
if not fp.read():
logger.notifyChannel('imap', netsvc.LOG_WARNING, 'lost internet connection !')
for server in self.browse(cr, uid, ids, context):
logger.notifyChannel('imap', netsvc.LOG_INFO, 'fetchmail start checking for new emails on %s' % (server.name))
@ -356,7 +366,7 @@ class email_server(osv.osv):
pop_server = POP3_SSL(server.server, int(server.port))
else:
pop_server = POP3(server.server, int(server.port))
#TODO: use this to remove only unread messages
#pop_server.user("recent:"+server.user)
pop_server.user(server.user)
@ -373,9 +383,10 @@ class email_server(osv.osv):
pop_server.quit()
logger.notifyChannel('imap', netsvc.LOG_INFO, 'fetchmail fetch %s email(s) from %s' % (numMsgs, server.name))
self.write(cr, uid, [server.id], {'state':'done'})
except Exception, e:
logger.notifyChannel('IMAP', netsvc.LOG_WARNING, '%s' % (e))
logger.notifyChannel(server.type, netsvc.LOG_WARNING, '%s' % (e))
return True

View File

@ -58,8 +58,7 @@
</notebook>
<group col="6" colspan="4">
<field name="state" select="1"/>
<button string="Verify Server" type="object" name="fetch_mail"/>
<button string="Schedule"/>
<button string="Fetch Emails" type="object" name="__fetch_mail"/>
</group>
</form>
</field>