Skip to content

Commit

Permalink
Graphical and Speed update
Browse files Browse the repository at this point in the history
v1.1 here !
Added an auto-update system and re worked the script for better speed and better design !
Patched some bugs to.
  • Loading branch information
ZKAW authored Jul 8, 2018
1 parent 6c74263 commit a482ed0
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 6 deletions.
5 changes: 4 additions & 1 deletion INSTALL
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
#github: https://github.com/ZKAW/VerifyMail


import time
import os
Expand Down Expand Up @@ -57,7 +59,7 @@ print(BLUE + "\n Fixing permissions...")
system('chmod +x verifymail')
system('chmod +x INSTALL')
system('chmod +x UNINSTALL')

system('chmod +x UPDATE')


print(BLUE + "\n Creating .verifymail config files in /root/.verifymail" + LIGHTBLUE)
Expand Down Expand Up @@ -89,3 +91,4 @@ shutil.copy2('verifymail', '/usr/bin/')
time.sleep(0.5)

print(BLUE + '\n The script is now installed, restart your terminal and type ' + LIGHTBLUE + '"verifymail"' + BLUE + '\n to launch it !\n')
quit()
30 changes: 30 additions & 0 deletions UPDATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
#github: https://github.com/ZKAW/VerifyMail

import urllib2,subprocess
version = urllib2.urlopen("https://raw.githubusercontent.com/ZKAW/VerifyMail/master/version.txt").read()
DEFAULT, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, LIGHTGRAY, DARKGRAY, LIGHTRED, LIGHTGREEN, LIGHTYELLOW, LIGHTBLUE, LIGHTMAGENTA, LIGHTCYAN, WHITE, GRAY = '\33[39m', '\33[30m', '\33[31m', '\33[32m', '\33[33m', '\33[34m', '\33[35m', '\33[36m', '\33[37m', '\33[90m', '\33[91m', '\33[92m', '\33[93m', '\33[94m', '\33[95m', '\33[96m', '\33[97m', '\33[30m'


def check_version(version):
with open("version.txt", "r") as vnumber:
if vnumber.read() != version:
return True
else:
return False


def main():

if check_version(version) is True:
subprocess.call(["git", "pull", "origin", "master"])
return " [✔] Successfully updated to latest version: v{0}".format(version)
if check_version(version) is False:
return " {2}[✔]{1} You are already up to date in {2}v{0}{1}".format(version, LIGHTBLUE, BLUE)
else:
return " {1}[✘]{0} An unknown {1}error{0} occurred during the update.\n".format(LIGHTRED, RED)

if __name__ == '__main__':
print("\n {1}Checking {0}if you are up to date{1}...{0}\n").format(LIGHTBLUE, BLUE)
print(main())
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pyDNS
validate_email
logging
205 changes: 201 additions & 4 deletions verifymail
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
#github: https://github.com/ZKAW/VerifyMail


import locale
import time
import os
import re
import smtplib
import logging
import socket

from os import system
from sys import stdout, exit

from validate_email import validate_email
#from validate_email import validate_email

results = []
lng = []
Expand Down Expand Up @@ -93,6 +98,15 @@ if 'fr' in lng:

ActualPathVar = " Chemin actuel: "

CanceledVar = '''
{0}************************************
{0}[!] {1}Recherche annulée ! {0}[!]
************************************
'''.format(RED, LIGHTRED)

else:

if 'de' in lng:
Expand Down Expand Up @@ -122,7 +136,7 @@ else:
{0}************************************
{0}[!] {1}Ungültigen Pfad {0}[!]
{0}[!] {1}Ungültigen Pfad {0}[!]
************************************
'''.format(RED, LIGHTRED)
Expand Down Expand Up @@ -154,6 +168,15 @@ else:

ActualPathVar = " Aktueller Pfad: "

CanceledVar = '''
{0}************************************
{0}[!] {1}Abgebrochene Suche ! {0}[!]
************************************
'''.format(RED, LIGHTRED)


else:

Expand Down Expand Up @@ -216,6 +239,15 @@ else:

ActualPathVar = " Camino actual: "

CanceledVar = '''
{0}************************************
{0}[!] {1}Búsqueda cancelada ! {0}[!]
************************************
'''.format(RED, LIGHTRED)


else:

Expand Down Expand Up @@ -277,6 +309,15 @@ else:

ActualPathVar = " Actual path: "

CanceledVar = '''
{0}************************************
{0}[!] {1}Canceled search ! {0}[!]
************************************
'''.format(RED, LIGHTRED)




Expand Down Expand Up @@ -308,6 +349,157 @@ def welcome():
{1}working on the impossible.'''.format(LIGHTGRAY, MAGENTA, LIGHTMAGENTA, LIGHTRED, RED, GRAY)


# THIS CODE IS IMPORTED FROM SCRIPT "valide_email.py" AT THE BEGINING I JUST
# IMPORTED IT BY THE COMMAND import valide_email BUT I HAD TO MODIFY SOMETHING
# IN THE SCRIPT THAT MAKED THE SCRIPT LOWER, SO THIS CODE BELLOW IS NOT FROM ME
# IT'S FROM (c) 2012 Syrus Akbary <[email protected]> THE REST OF THE CODE IS
# FROM ME.

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 + '$'

MX_DNS_CACHE = {}
MX_CHECK_CACHE = {}



try:
raw_input
except NameError:
def raw_input(prompt=''):
return input(prompt)

try:
import DNS
ServerError = DNS.ServerError
DNS.DiscoverNameServers()
except (ImportError, AttributeError):
DNS = None

class ServerError(Exception):
pass


def get_mx_ip(hostname):
if hostname not in MX_DNS_CACHE:
try:
MX_DNS_CACHE[hostname] = DNS.mxlookup(hostname)
except ServerError as e:
if e.rcode == 3: # NXDOMAIN (Non-Existent Domain)
MX_DNS_CACHE[hostname] = None
else:
raise

return MX_DNS_CACHE[hostname]


def validate_email(email, check_mx=False, verify=False, debug=False, smtp_timeout=1):

if debug:
logger = logging.getLogger('validate_email')
logger.setLevel(logging.DEBUG)
else:
logger = None

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')
hostname = email[email.find('@') + 1:]
mx_hosts = get_mx_ip(hostname)
if mx_hosts is None:
return False
for mx in mx_hosts:
try:
if not verify and mx[1] in MX_CHECK_CACHE:
return MX_CHECK_CACHE[mx[1]]
smtp = smtplib.SMTP(timeout=smtp_timeout)
smtp.connect(mx[1])
MX_CHECK_CACHE[mx[1]] = True
if not verify:
try:
smtp.quit()
except smtplib.SMTPServerDisconnected:
pass
return True
status, _ = smtp.helo()
if status != 250:
smtp.quit()
if debug:
logger.debug(u'%s answer: %s - %s', mx[1], status, _)
continue
smtp.mail('')
status, _ = smtp.rcpt(email)
if status == 250:
smtp.quit()
return True
if debug:
logger.debug(u'%s answer: %s - %s', mx[1], status, _)
smtp.quit()
except smtplib.SMTPServerDisconnected: # Server not permits verify user
if debug:
logger.debug(u'%s disconected.', mx[1])
except smtplib.SMTPConnectError:
if debug:
logger.debug(u'Unable to connect to %s.', mx[1])
return None
except AssertionError:
return False
except (ServerError, socket.error) as e:
if debug:
logger.debug('ServerError or socket.error exception raised (%s).', e)
return None
return True


# END OF THE IMPORTED CODE FROM SCRIPT valide_email.py







def multi():

Expand All @@ -316,6 +508,7 @@ def multi():
try:
results = []
os.chdir(listfldr)
StoppedVar = InvalidPathVar
print("\n" + LIGHTBLUE + ActualPathVar + BLUE + os.getcwd() + "/\n")
lists = os.listdir(listfldr)
print(lists)
Expand All @@ -332,6 +525,7 @@ def multi():
results.append(line.strip())

count = 0
StoppedVar = CanceledVar
for i in results:
is_valid = validate_email(i,verify=True)
count += 1
Expand Down Expand Up @@ -378,12 +572,14 @@ def multi():
if ask.upper() == "0":
exit(0)
except:
exit(0)
StoppedVar = ""
quit()

except:

results = []
system('clear')
print(InvalidPathVar)
print(StoppedVar)
aide()
while True:
try:
Expand All @@ -398,6 +594,7 @@ def multi():
exit(0)

except:
StoppedVar = ""
exit(0)


Expand Down

0 comments on commit a482ed0

Please sign in to comment.