summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorOlivier Dony <odo@openerp.com>2017-08-18 13:19:23 +0200
committerOlivier Dony <odo@openerp.com>2017-08-20 23:25:54 +0200
commit92e8a342c964762c4a4c668140d05f3c14e4fd2d (patch)
tree40b7e57cdc00c39de271f79df5471ab56be01ac4 /addons
parent555ff9ab8405a3ab0ac9e73c35a9313c737b1386 (diff)
[FIX] P3: crm: dead code removal + simplify
Merge wizard contained dead code with references to an unused lib for validating emails. Removing everything is easier. + remove unnecessary pycompat wrapping for safe use of dict.items()
Diffstat (limited to 'addons')
-rw-r--r--addons/crm/wizard/base_partner_merge.py44
-rw-r--r--addons/crm/wizard/validate_email.py123
2 files changed, 3 insertions, 164 deletions
diff --git a/addons/crm/wizard/base_partner_merge.py b/addons/crm/wizard/base_partner_merge.py
index 24a573ad871..a91b9ec3dc1 100644
--- a/addons/crm/wizard/base_partner_merge.py
+++ b/addons/crm/wizard/base_partner_merge.py
@@ -2,56 +2,18 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from ast import literal_eval
-from email.utils import parseaddr
import functools
-try:
- from html.entities import entitydefs
-except ImportError:
- from htmlentitydefs import entitydefs # pylint: disable=deprecated-module
import itertools
import logging
-import operator
import psycopg2
-import re
-
-# Validation Library https://pypi.python.org/pypi/validate_email/1.1
-from .validate_email import validate_email
from odoo import api, fields, models
from odoo import SUPERUSER_ID, _
from odoo.exceptions import ValidationError, UserError
-from odoo.tools import mute_logger, pycompat
+from odoo.tools import mute_logger
_logger = logging.getLogger('base.partner.merge')
-
-# http://www.php2python.com/wiki/function.html-entity-decode/
-def html_entity_decode_char(m, defs=entitydefs):
- try:
- return defs[m.group(1)]
- except KeyError:
- return m.group(0)
-
-
-def html_entity_decode(string):
- pattern = re.compile("&(\w+?);")
- return pattern.sub(html_entity_decode_char, string)
-
-
-def sanitize_email(email):
- assert isinstance(email, pycompat.string_types) and email
-
- result = re.subn(r';|/|:', ',', html_entity_decode(email or ''))[0].split(',')
-
- emails = [parseaddr(email)[1]
- for item in result
- for email in item.split()]
-
- return [email.lower()
- for email in emails
- if validate_email(email)]
-
-
class MergePartnerLine(models.TransientModel):
_name = 'base.partner.merge.line'
@@ -271,7 +233,7 @@ class MergePartnerAutomatic(models.TransientModel):
return item
# get all fields that are not computed or x2many
values = dict()
- for column, field in pycompat.items(model_fields):
+ for column, field in model_fields.items():
if field.type not in ('many2many', 'one2many') and field.compute is None:
for item in itertools.chain(src_partners, [dst_partner]):
if item[column]:
@@ -409,7 +371,7 @@ class MergePartnerAutomatic(models.TransientModel):
"""
return any(
self.env[model].search_count([(field, 'in', aggr_ids)])
- for model, field in pycompat.items(models)
+ for model, field in models.items()
)
@api.model
diff --git a/addons/crm/wizard/validate_email.py b/addons/crm/wizard/validate_email.py
deleted file mode 100644
index 38de5743fca..00000000000
--- a/addons/crm/wizard/validate_email.py
+++ /dev/null
@@ -1,123 +0,0 @@
-# RFC 2822 - style email validation for Python
-# (c) 2012 Syrus Akbary <me@syrusakbary.com>
-# Extended from (c) 2011 Noel Bush <noel@aitools.org>
-# for support of mx and user check
-# This code is made available to you under the GNU LGPL v3.
-#
-# This module provides a single method, valid_email_address(),
-# which returns True or False to indicate whether a given address
-# is valid according to the 'addr-spec' part of the specification
-# given in RFC 2822. Ideally, we would like to find this
-# in some other library, already thoroughly tested and well-
-# maintained. The standard Python library email.utils
-# contains a parse_addr() function, but it is not sufficient
-# to detect many malformed addresses.
-#
-# This implementation aims to be faithful to the RFC, with the
-# exception of a circular definition (see comments below), and
-# with the omission of the pattern components marked as "obsolete".
-
-import re
-import smtplib
-import socket
-
-try:
- import DNS
- ServerError = DNS.ServerError
-except:
- DNS = None
- class ServerError(Exception): pass
-# All we are really doing is comparing the input string to one
-# gigantic regular expression. But building that regexp, and
-# ensuring its correctness, is made much easier by assembling it
-# from the "tokens" defined by the RFC. Each of these tokens is
-# tested in the accompanying unit test file.
-#
-# The section of RFC 2822 from which each pattern component is
-# derived is given in an accompanying comment.
-#
-# (To make things simple, every string below is given as 'raw',
-# even when it's not strictly necessary. This way we don't forget
-# when it is necessary.)
-#
-WSP = r'[ \t]' # see 2.2.2. Structured Header Field Bodies
-CRLF = r'(?:\r\n)' # see 2.2.3. Long Header Fields
-NO_WS_CTL = r'\x01-\x08\x0b\x0c\x0f-\x1f\x7f' # see 3.2.1. Primitive Tokens
-QUOTED_PAIR = r'(?:\\.)' # see 3.2.2. Quoted characters
-FWS = r'(?:(?:' + WSP + r'*' + CRLF + r')?' + \
- WSP + r'+)' # see 3.2.3. Folding white space and comments
-CTEXT = r'[' + NO_WS_CTL + \
- r'\x21-\x27\x2a-\x5b\x5d-\x7e]' # see 3.2.3
-CCONTENT = r'(?:' + CTEXT + r'|' + \
- QUOTED_PAIR + r')' # see 3.2.3 (NB: The RFC includes COMMENT here
- # as well, but that would be circular.)
-COMMENT = r'\((?:' + FWS + r'?' + CCONTENT + \
- r')*' + FWS + r'?\)' # see 3.2.3
-CFWS = r'(?:' + FWS + r'?' + COMMENT + ')*(?:' + \
- FWS + '?' + COMMENT + '|' + FWS + ')' # see 3.2.3
-ATEXT = r'[\w!#$%&\'\*\+\-/=\?\^`\{\|\}~]' # see 3.2.4. Atom
-ATOM = CFWS + r'?' + ATEXT + r'+' + CFWS + r'?' # see 3.2.4
-DOT_ATOM_TEXT = ATEXT + r'+(?:\.' + ATEXT + r'+)*' # see 3.2.4
-DOT_ATOM = CFWS + r'?' + DOT_ATOM_TEXT + CFWS + r'?' # see 3.2.4
-QTEXT = r'[' + NO_WS_CTL + \
- r'\x21\x23-\x5b\x5d-\x7e]' # see 3.2.5. Quoted strings
-QCONTENT = r'(?:' + QTEXT + r'|' + \
- QUOTED_PAIR + r')' # see 3.2.5
-QUOTED_STRING = CFWS + r'?' + r'"(?:' + FWS + \
- r'?' + QCONTENT + r')*' + FWS + \
- r'?' + r'"' + CFWS + r'?'
-LOCAL_PART = r'(?:' + DOT_ATOM + r'|' + \
- QUOTED_STRING + r')' # see 3.4.1. Addr-spec specification
-DTEXT = r'[' + NO_WS_CTL + r'\x21-\x5a\x5e-\x7e]' # see 3.4.1
-DCONTENT = r'(?:' + DTEXT + r'|' + \
- QUOTED_PAIR + r')' # see 3.4.1
-DOMAIN_LITERAL = CFWS + r'?' + r'\[' + \
- r'(?:' + FWS + r'?' + DCONTENT + \
- r')*' + FWS + r'?\]' + CFWS + r'?' # see 3.4.1
-DOMAIN = r'(?:' + DOT_ATOM + r'|' + \
- DOMAIN_LITERAL + r')' # see 3.4.1
-ADDR_SPEC = LOCAL_PART + r'@' + DOMAIN # see 3.4.1
-
-# A valid address will match exactly the 3.4.1 addr-spec.
-VALID_ADDRESS_REGEXP = '^' + ADDR_SPEC + '$'
-
-def validate_email(email, check_mx=False,verify=False):
-
- """Indicate whether the given string is a valid email address
- according to the 'addr-spec' portion of RFC 2822 (see section
- 3.4.1). Parts of the spec that are marked obsolete are *not*
- included in this test, and certain arcane constructions that
- depend on circular definitions in the spec may not pass, but in
- general this should correctly identify any email address likely
- to be in use as of 2011."""
- try:
- assert re.match(VALID_ADDRESS_REGEXP, email) is not None
- check_mx |= verify
- if check_mx:
- if not DNS: raise Exception('For check the mx records or check if the email exists you must have installed pyDNS python package')
- DNS.DiscoverNameServers()
- hostname = email[email.find('@')+1:]
- mx_hosts = DNS.mxlookup(hostname)
- for mx in mx_hosts:
- try:
- smtp = smtplib.SMTP()
- smtp.connect(mx[1])
- if not verify: return True
- status, _ = smtp.helo()
- if status != 250: continue
- smtp.mail('')
- status, _ = smtp.rcpt(email)
- if status != 250: return False
- break
- except smtplib.SMTPServerDisconnected: #Server not permits verify user
- break
- except smtplib.SMTPConnectError:
- continue
- except (AssertionError, ServerError):
- return False
- return True
-
-# import sys
-
-# sys.modules[__name__],sys.modules['validate_email_module'] = validate_email,sys.modules[__name__]
-# from validate_email_module import *