2
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
4
4
5
- use std:: { borrow:: Cow , collections:: HashMap } ;
6
-
7
5
use rocket:: {
8
6
data:: { self , FromData } , http:: Status , response:: Failure , Data , Outcome , Request ,
9
7
} ;
10
8
use rocket_contrib:: { Json , Value } ;
11
- use validator:: { self , Validate , ValidationError } ;
12
9
13
10
use auth_db:: DbClient ;
14
11
use bounces:: Bounces ;
12
+ use deserialize;
15
13
use providers:: Providers ;
16
14
use settings:: Settings ;
17
15
use validate;
@@ -32,9 +30,9 @@ struct Body {
32
30
html : Option < String > ,
33
31
}
34
32
35
- #[ derive( Debug , Deserialize , Validate ) ]
33
+ #[ derive( Debug , Deserialize ) ]
36
34
struct Email {
37
- #[ validate ( email ) ]
35
+ #[ serde ( deserialize_with = "deserialize::email_address" ) ]
38
36
to : String ,
39
37
cc : Option < Vec < String > > ,
40
38
subject : String ,
@@ -43,7 +41,7 @@ struct Email {
43
41
}
44
42
45
43
impl FromData for Email {
46
- type Error = ValidationError ;
44
+ type Error = ( ) ;
47
45
48
46
fn from_data ( request : & Request , data : Data ) -> data:: Outcome < Self , Self :: Error > {
49
47
let result = Json :: < Email > :: from_data ( request, data) ;
@@ -65,7 +63,7 @@ impl FromData for Email {
65
63
fn validate ( email : & Email ) -> bool {
66
64
if let Some ( ref cc) = email. cc {
67
65
for address in cc {
68
- if !validator :: validate_email ( & address) {
66
+ if !validate :: email_address ( & address) {
69
67
return false ;
70
68
}
71
69
}
@@ -80,15 +78,8 @@ fn validate(email: &Email) -> bool {
80
78
true
81
79
}
82
80
83
- fn fail ( ) -> data:: Outcome < Email , ValidationError > {
84
- Outcome :: Failure ( (
85
- Status :: BadRequest ,
86
- ValidationError {
87
- code : Cow :: from ( "400" ) ,
88
- message : None ,
89
- params : HashMap :: new ( ) ,
90
- } ,
91
- ) )
81
+ fn fail ( ) -> data:: Outcome < Email , ( ) > {
82
+ Outcome :: Failure ( ( Status :: BadRequest , ( ) ) )
92
83
}
93
84
94
85
#[ post( "/send" , format = "application/json" , data = "<email>" ) ]
0 commit comments