|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace andmemasin\emailsvalidator\models; |
|
4
|
|
|
|
|
5
|
|
|
use andmemasin\emailsvalidator\Module; |
|
6
|
|
|
use yii\base\Model; |
|
7
|
|
|
use yii; |
|
8
|
|
|
|
|
9
|
|
|
class EmailsValidationForm extends Model |
|
10
|
|
|
{ |
|
11
|
|
|
//TODO find me a better name! |
|
12
|
|
|
/** @var string */ |
|
13
|
|
|
public $textInput; |
|
14
|
|
|
|
|
15
|
|
|
/** @var Module */ |
|
16
|
|
|
public $module; |
|
17
|
|
|
|
|
18
|
|
|
/** @var EmailAddress[] $emailAddresses */ |
|
19
|
|
|
public $emailAddresses = []; |
|
20
|
|
|
|
|
21
|
|
|
/** @var EmailAddress[] $failingEmailAddresses */ |
|
22
|
|
|
public $failingEmailAddresses = []; |
|
23
|
|
|
|
|
24
|
|
|
/** @var boolean */ |
|
25
|
|
|
public $checkDNS = true; |
|
26
|
|
|
|
|
27
|
|
|
/** @var boolean */ |
|
28
|
|
|
public $checkSpoof = true; |
|
29
|
|
|
|
|
30
|
|
|
/** @var boolean */ |
|
31
|
|
|
public $displayOnlyProblems = true; |
|
32
|
|
|
|
|
33
|
|
|
/** @var array Array of already checked domains */ |
|
34
|
|
|
public $checkedDomains = []; |
|
35
|
|
|
|
|
36
|
|
|
public function init() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->module = \Yii::$app->getModule('emailsvalidator'); |
|
39
|
|
|
parent::init(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function rules() |
|
43
|
|
|
{ |
|
44
|
|
|
return [ |
|
45
|
|
|
[['textInput'], 'required'], |
|
46
|
|
|
[['textInput'], 'string', 'max' => 1024 * $this->module->maxInputKB], |
|
47
|
|
|
[['checkDNS','checkSpoof','displayOnlyProblems'],'boolean'], |
|
48
|
|
|
]; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function attributeLabels() |
|
52
|
|
|
{ |
|
53
|
|
|
return [ |
|
54
|
|
|
'textInput'=>Yii::t('app','E-mail addresses'), |
|
55
|
|
|
'checkDNS'=>Yii::t('app','Perform DNS check'), |
|
56
|
|
|
'checkSpoof'=>Yii::t('app','Perform spoofing check'), |
|
57
|
|
|
'displayOnlyProblems'=>Yii::t('app','Display only e-mails with problems in results'), |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function attributeHints() |
|
62
|
|
|
{ |
|
63
|
|
|
return [ |
|
64
|
|
|
'textInput'=>Yii::t('app','One e-mail address per line'), |
|
65
|
|
|
'checkDNS'=>Yii::t('app','Checking DNS will increase processing time'), |
|
66
|
|
|
]; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function process(){ |
|
70
|
|
|
$this->loadEmailAddresses(); |
|
71
|
|
|
return true; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
private function loadEmailAddresses(){ |
|
75
|
|
|
if($this->textInput){ |
|
76
|
|
|
$pattern = '/\r\n|[\r\n]/'; |
|
77
|
|
|
$array = preg_split( $pattern, $this->textInput ); |
|
78
|
|
|
if(!empty($array)){ |
|
79
|
|
|
foreach ($array as $address){ |
|
80
|
|
|
if($address){ |
|
81
|
|
|
$model = new EmailAddress([ |
|
82
|
|
|
'address'=>$address, |
|
83
|
|
|
'checkDNS'=>$this->checkDNS, |
|
84
|
|
|
'checkSpoof'=>$this->checkSpoof, |
|
85
|
|
|
]); |
|
86
|
|
|
|
|
87
|
|
|
$this->emailAddresses[] = $model; |
|
88
|
|
|
if(!$model->isValid){ |
|
89
|
|
|
$this->failingEmailAddresses[] = $model; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
} |