@@ -1206,79 +1206,45 @@ def validate_ip4_operation_status(global_translation, rating, local_translation,
1206
1206
rating += ipv4_operational_rating
1207
1207
return rating
1208
1208
1209
-
1210
- def validate_mx_records (global_translation , rating , result_dict , local_translation , hostname ):
1211
- email_results = dns_lookup (hostname , dns .rdatatype .MX )
1212
- email_servers = []
1213
- # 1.1 - Check IPv4 and IPv6 support
1214
- ipv4_servers = []
1215
- ipv6_servers = []
1209
+ def get_email_entries (hostname ):
1216
1210
email_entries = []
1217
-
1211
+ email_results = dns_lookup ( hostname , dns . rdatatype . MX )
1218
1212
has_mx_records = len (email_results ) > 0
1219
1213
if not has_mx_records :
1220
- return rating , ipv4_servers , ipv6_servers
1214
+ return email_entries
1221
1215
1222
1216
for email_result in email_results :
1223
1217
# result is in format "<priority> <domain address/ip>"
1224
1218
email_result_sections = email_result .split (' ' )
1225
1219
if len (email_result_sections ) > 1 :
1226
1220
server_address = email_result_sections [1 ]
1227
1221
else :
1228
- return rating , ipv4_servers , ipv6_servers
1222
+ return email_entries
1229
1223
1230
1224
email_entries .append (server_address )
1231
- ipv_4 = dns_lookup (server_address , dns .rdatatype .A )
1232
- ipv_6 = dns_lookup (server_address , dns .rdatatype .AAAA )
1233
1225
1226
+ return email_entries
1227
+
1228
+ def get_addresses_for_dnstype (email_entries , rdatatype ):
1229
+ ipv4_servers = []
1230
+ for email_entry in email_entries :
1231
+ ipv_4 = dns_lookup (email_entry , rdatatype )
1234
1232
ipv4_servers .extend (ipv_4 )
1235
- ipv6_servers . extend ( ipv_6 )
1233
+ return ipv4_servers
1236
1234
1235
+ def validate_mx_records (global_translation , rating , result_dict , local_translation , hostname ):
1236
+ # 1.1 - Check IPv4 and IPv6 support
1237
+ email_entries = get_email_entries (hostname )
1238
+
1239
+ ipv4_servers = get_addresses_for_dnstype (email_entries , dns .rdatatype .A )
1240
+ ipv6_servers = get_addresses_for_dnstype (email_entries , dns .rdatatype .AAAA )
1241
+
1242
+ email_servers = []
1237
1243
email_servers .extend (ipv4_servers )
1238
1244
email_servers .extend (ipv6_servers )
1239
1245
1240
- nof_ipv4_servers = len (ipv4_servers )
1241
- nof_ipv4_rating = Rating (global_translation , REVIEW_SHOW_IMPROVEMENTS_ONLY )
1242
- if nof_ipv4_servers >= 2 :
1243
- nof_ipv4_rating .set_overall (5.0 )
1244
- nof_ipv4_rating .set_integrity_and_security (
1245
- 5.0 , local_translation ('TEXT_REVIEW_IPV4_REDUNDANCE' ))
1246
- nof_ipv4_rating .set_standards (
1247
- 5.0 , local_translation ('TEXT_REVIEW_IPV4_SUPPORT' ))
1248
- elif nof_ipv4_servers == 1 :
1249
- # example: feber.se (do dns lookup also before)
1250
- nof_ipv4_rating .set_overall (2.5 )
1251
- nof_ipv4_rating .set_integrity_and_security (
1252
- 1.0 , local_translation ('TEXT_REVIEW_IPV4_NO_REDUNDANCE' ))
1253
- nof_ipv4_rating .set_standards (
1254
- 5.0 , local_translation ('TEXT_REVIEW_IPV4_SUPPORT' ))
1255
- else :
1256
- nof_ipv4_rating .set_overall (1.0 )
1257
- nof_ipv4_rating .set_standards (
1258
- 1.0 , local_translation ('TEXT_REVIEW_IPV4_NO_SUPPORT' ))
1259
- rating += nof_ipv4_rating
1260
-
1261
- nof_ipv6_servers = len (ipv6_servers )
1262
- nof_ipv6_rating = Rating (global_translation , REVIEW_SHOW_IMPROVEMENTS_ONLY )
1263
- if nof_ipv6_servers >= 2 :
1264
- nof_ipv6_rating .set_overall (5.0 )
1265
- nof_ipv6_rating .set_integrity_and_security (
1266
- 5.0 , local_translation ('TEXT_REVIEW_IPV6_REDUNDANCE' ))
1267
- nof_ipv6_rating .set_standards (
1268
- 5.0 , local_translation ('TEXT_REVIEW_IPV6_SUPPORT' ))
1269
- elif nof_ipv6_servers == 1 :
1270
- # example: feber.se (do dns lookup also before)
1271
- nof_ipv6_rating .set_overall (2.5 )
1272
- nof_ipv6_rating .set_integrity_and_security (
1273
- 1.0 , local_translation ('TEXT_REVIEW_IPV6_NO_REDUNDANCE' ))
1274
- nof_ipv6_rating .set_standards (
1275
- 5.0 , local_translation ('TEXT_REVIEW_IPV6_SUPPORT' ))
1276
- else :
1277
- # example: huddinge.se
1278
- nof_ipv6_rating .set_overall (1.0 )
1279
- nof_ipv6_rating .set_standards (
1280
- 1.0 , local_translation ('TEXT_REVIEW_IPV6_NO_SUPPORT' ))
1281
- rating += nof_ipv6_rating
1246
+ rating += rate_mx_ip4_usage (global_translation , local_translation , ipv4_servers )
1247
+ rating += rate_mx_ip6_usage (global_translation , local_translation , ipv6_servers )
1282
1248
1283
1249
# 2.0 - Check GDPR for all IP-adresses
1284
1250
countries_others = {}
@@ -1302,6 +1268,27 @@ def validate_mx_records(global_translation, rating, result_dict, local_translati
1302
1268
else :
1303
1269
countries_others [country_code ] = 1
1304
1270
1271
+ rating += rate_mx_gdpr (
1272
+ global_translation ,
1273
+ local_translation ,
1274
+ countries_others ,
1275
+ countries_eu_or_exception_list )
1276
+
1277
+ # add data to result of test
1278
+ result_dict ["mx-addresses" ] = email_entries
1279
+ result_dict ["mx-ipv4-servers" ] = ipv4_servers
1280
+ result_dict ["mx-ipv6-servers" ] = ipv6_servers
1281
+ result_dict ["mx-gdpr-countries" ] = countries_eu_or_exception_list
1282
+ result_dict ["mx-none-gdpr-countries" ] = countries_others
1283
+
1284
+ return rating , ipv4_servers , ipv6_servers
1285
+
1286
+ def rate_mx_gdpr (
1287
+ global_translation ,
1288
+ local_translation ,
1289
+ countries_others ,
1290
+ countries_eu_or_exception_list ):
1291
+ rating = Rating (global_translation , REVIEW_SHOW_IMPROVEMENTS_ONLY )
1305
1292
nof_gdpr_countries = len (countries_eu_or_exception_list )
1306
1293
nof_none_gdpr_countries = len (countries_others )
1307
1294
if nof_gdpr_countries > 0 :
@@ -1318,12 +1305,50 @@ def validate_mx_records(global_translation, rating, result_dict, local_translati
1318
1305
1.0 , local_translation ('TEXT_REVIEW_MX_NONE_GDPR' ).format (
1319
1306
', ' .join (countries_others .keys ())))
1320
1307
rating += none_gdpr_rating
1308
+ return rating
1321
1309
1322
- # add data to result of test
1323
- result_dict ["mx-addresses" ] = email_entries
1324
- result_dict ["mx-ipv4-servers" ] = ipv4_servers
1325
- result_dict ["mx-ipv6-servers" ] = ipv6_servers
1326
- result_dict ["mx-gdpr-countries" ] = countries_eu_or_exception_list
1327
- result_dict ["mx-none-gdpr-countries" ] = countries_others
1310
+ def rate_mx_ip6_usage (global_translation , local_translation , ipv6_servers ):
1311
+ nof_ipv6_servers = len (ipv6_servers )
1312
+ nof_ipv6_rating = Rating (global_translation , REVIEW_SHOW_IMPROVEMENTS_ONLY )
1313
+ if nof_ipv6_servers >= 2 :
1314
+ nof_ipv6_rating .set_overall (5.0 )
1315
+ nof_ipv6_rating .set_integrity_and_security (
1316
+ 5.0 , local_translation ('TEXT_REVIEW_IPV6_REDUNDANCE' ))
1317
+ nof_ipv6_rating .set_standards (
1318
+ 5.0 , local_translation ('TEXT_REVIEW_IPV6_SUPPORT' ))
1319
+ elif nof_ipv6_servers == 1 :
1320
+ # example: feber.se (do dns lookup also before)
1321
+ nof_ipv6_rating .set_overall (2.5 )
1322
+ nof_ipv6_rating .set_integrity_and_security (
1323
+ 1.0 , local_translation ('TEXT_REVIEW_IPV6_NO_REDUNDANCE' ))
1324
+ nof_ipv6_rating .set_standards (
1325
+ 5.0 , local_translation ('TEXT_REVIEW_IPV6_SUPPORT' ))
1326
+ else :
1327
+ # example: huddinge.se
1328
+ nof_ipv6_rating .set_overall (1.0 )
1329
+ nof_ipv6_rating .set_standards (
1330
+ 1.0 , local_translation ('TEXT_REVIEW_IPV6_NO_SUPPORT' ))
1328
1331
1329
- return rating , ipv4_servers , ipv6_servers
1332
+ return nof_ipv6_rating
1333
+
1334
+ def rate_mx_ip4_usage (global_translation , local_translation , ipv4_servers ):
1335
+ nof_ipv4_servers = len (ipv4_servers )
1336
+ nof_ipv4_rating = Rating (global_translation , REVIEW_SHOW_IMPROVEMENTS_ONLY )
1337
+ if nof_ipv4_servers >= 2 :
1338
+ nof_ipv4_rating .set_overall (5.0 )
1339
+ nof_ipv4_rating .set_integrity_and_security (
1340
+ 5.0 , local_translation ('TEXT_REVIEW_IPV4_REDUNDANCE' ))
1341
+ nof_ipv4_rating .set_standards (
1342
+ 5.0 , local_translation ('TEXT_REVIEW_IPV4_SUPPORT' ))
1343
+ elif nof_ipv4_servers == 1 :
1344
+ # example: feber.se (do dns lookup also before)
1345
+ nof_ipv4_rating .set_overall (2.5 )
1346
+ nof_ipv4_rating .set_integrity_and_security (
1347
+ 1.0 , local_translation ('TEXT_REVIEW_IPV4_NO_REDUNDANCE' ))
1348
+ nof_ipv4_rating .set_standards (
1349
+ 5.0 , local_translation ('TEXT_REVIEW_IPV4_SUPPORT' ))
1350
+ else :
1351
+ nof_ipv4_rating .set_overall (1.0 )
1352
+ nof_ipv4_rating .set_standards (
1353
+ 1.0 , local_translation ('TEXT_REVIEW_IPV4_NO_SUPPORT' ))
1354
+ return nof_ipv4_rating
0 commit comments