Skip to content

Commit c55253e

Browse files
author
resteve
committed
[IMP] Check emails is valid. If not valid, this email go to draft mailbox
1 parent 652f768 commit c55253e

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

poweremail_mailbox.py

+25
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,31 @@ def complete_mail(self, cr, uid, ids, context=None):
157157
self.pool.get('poweremail.core_accounts').get_fullmail(cr, uid, id, context)
158158
self.historise(cr, uid, [id], "Full email downloaded", context)
159159

160+
def check_email_valid(self, email):
161+
"""Check if email is valid. Check @ and .
162+
:email str
163+
return True/False
164+
"""
165+
def get_validate_email(email):
166+
sep=[x for x in email if not x.isalpha()]
167+
sepjoined=''.join(sep)
168+
if sepjoined.strip('.') != '@': return False
169+
for i in sep:
170+
part,i,email=email.partition(i)
171+
if len(part)<2: return False
172+
return True
173+
174+
if not email:
175+
return False
176+
177+
emails = email.split(',')
178+
if len(emails)>0:
179+
for email in emails:
180+
if not get_validate_email(email):
181+
return False
182+
break
183+
return True
184+
160185
_columns = {
161186
'pem_from':fields.char(
162187
'From',

poweremail_send_wizard.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import netsvc
2929
import base64
3030
import time
31+
import re
3132
from tools.translate import _
3233
import tools
3334
from poweremail_template import get_value
@@ -190,8 +191,24 @@ def sav_to_drafts(self, cr, uid, ids, context=None):
190191
def send_mail(self, cr, uid, ids, context=None):
191192
if context is None:
192193
context = {}
194+
mailbox_obj = self.pool.get('poweremail.mailbox')
195+
values = {'folder':'outbox'}
196+
check_email = True
197+
193198
mailid = self.save_to_mailbox(cr, uid, ids, context)
194-
if self.pool.get('poweremail.mailbox').write(cr, uid, mailid, {'folder':'outbox'}, context):
199+
200+
if len(mailid)>0:
201+
mail = mailbox_obj.browse(cr, uid, mailid[0], context)
202+
check_email = mail.pem_to and mailbox_obj.check_email_valid(mail.pem_to) or False
203+
if mail.pem_cc:
204+
check_email = check_email and mailbox_obj.check_email_valid(mail.pem_cc)
205+
if mail.pem_bcc:
206+
check_email = check_email and mailbox_obj.check_email_valid(mail.pem_bcc)
207+
208+
if not check_email:
209+
values = {'folder':'drafts'}
210+
211+
if mailbox_obj.write(cr, uid, mailid, values, context):
195212
return {'type':'ir.actions.act_window_close' }
196213

197214
def get_generated(self, cr, uid, ids=None, context=None):

0 commit comments

Comments
 (0)