-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproviders.py
More file actions
99 lines (90 loc) · 2.95 KB
/
Copy pathproviders.py
File metadata and controls
99 lines (90 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import re
import dns.resolver
import logging
# MX record patterns to identify providers
MX_PATTERNS = {
'google': {
'patterns': ['google.com', 'googlemail.com', 'gmail.com'],
'name': 'Gmail',
'webmail_url': 'https://mail.google.com',
'icon': 'fab fa-google'
},
'microsoft': {
'patterns': ['outlook.com', 'protection.outlook.com', 'hotmail.com'],
'name': 'Outlook',
'webmail_url': 'https://outlook.office.com',
'icon': 'fab fa-microsoft'
},
'yahoo': {
'patterns': ['yahoo.com', 'yahoodns.net'],
'name': 'Yahoo Mail',
'webmail_url': 'https://mail.yahoo.com',
'icon': 'fab fa-yahoo'
},
'protonmail': {
'patterns': ['protonmail.ch', 'proton.me'],
'name': 'ProtonMail',
'webmail_url': 'https://mail.proton.me',
'icon': 'fas fa-shield-alt'
},
'zoho': {
'patterns': ['zoho.com', 'zoho.eu'],
'name': 'Zoho Mail',
'webmail_url': 'https://mail.zoho.com',
'icon': 'fas fa-envelope'
},
'apple': {
'patterns': ['icloud.com', 'apple.com'],
'name': 'iCloud Mail',
'webmail_url': 'https://www.icloud.com/mail',
'icon': 'fab fa-apple'
}
}
def get_mx_records(domain):
"""Get MX records for a domain"""
try:
mx_records = dns.resolver.resolve(domain, 'MX')
return [str(mx.exchange).rstrip('.').lower() for mx in mx_records]
except Exception as e:
logging.error(f"Error looking up MX records for {domain}: {str(e)}")
return []
def detect_provider_from_mx(mx_records):
"""Detect email provider from MX records"""
if not mx_records:
return None
for mx_record in mx_records:
for provider, info in MX_PATTERNS.items():
if any(pattern in mx_record for pattern in info['patterns']):
return {
'provider': info['name'],
'webmail_url': info['webmail_url'],
'icon': info['icon'],
'detection_method': 'mx_record'
}
return None
def get_provider_info(email):
"""
Extract domain from email and return provider information
"""
try:
domain = email.split('@')[1].lower()
result = {'domain': domain}
# Get MX records
mx_records = get_mx_records(domain)
result['mx_records'] = mx_records
# Try to detect provider from MX records
provider_info = detect_provider_from_mx(mx_records)
if provider_info:
result.update(provider_info)
return result
# If no provider detected
result.update({
'provider': 'Unable to detect provider',
'webmail_url': None,
'icon': 'fas fa-question-circle',
'detection_method': 'unknown'
})
return result
except Exception as e:
logging.error(f"Error processing email: {str(e)}")
return None