1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.mail.internal.factory.usersandgroups; |
21 |
|
|
22 |
|
import javax.mail.Address; |
23 |
|
import javax.mail.internet.AddressException; |
24 |
|
import javax.mail.internet.InternetAddress; |
25 |
|
|
26 |
|
import org.apache.commons.lang3.StringUtils; |
27 |
|
import org.slf4j.Logger; |
28 |
|
import org.slf4j.LoggerFactory; |
29 |
|
import org.xwiki.model.reference.DocumentReference; |
30 |
|
|
31 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
32 |
|
import com.xpn.xwiki.internal.plugin.rightsmanager.UserDataExtractor; |
33 |
|
import com.xpn.xwiki.objects.BaseObject; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@version |
39 |
|
@since |
40 |
|
@since |
41 |
|
|
|
|
| 73.3% |
Uncovered Elements: 4 (15) |
Complexity: 5 |
Complexity Density: 0.5 |
|
42 |
|
public class AddressUserDataExtractor implements UserDataExtractor<Address> |
43 |
|
{ |
44 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(AddressUserDataExtractor.class); |
45 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
46 |
0 |
@Override... |
47 |
|
public Address extractFromSuperadmin(DocumentReference reference) |
48 |
|
{ |
49 |
0 |
return null; |
50 |
|
} |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
0 |
@Override... |
53 |
|
public Address extractFromGuest(DocumentReference reference) |
54 |
|
{ |
55 |
0 |
return null; |
56 |
|
} |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
58 |
17 |
@Override... |
59 |
|
public Address extract(DocumentReference reference, XWikiDocument document, BaseObject userObject) |
60 |
|
{ |
61 |
17 |
Address address = null; |
62 |
|
|
63 |
|
|
64 |
17 |
String email = userObject.getStringValue("email"); |
65 |
17 |
if (!StringUtils.isBlank(email)) { |
66 |
|
|
67 |
16 |
try { |
68 |
16 |
address = InternetAddress.parse(email)[0]; |
69 |
|
} catch (AddressException e) { |
70 |
|
|
71 |
1 |
LOGGER.warn("Found invalid email address [{}] for user [{}]. Email will not been sent to that user.", |
72 |
|
email, reference); |
73 |
|
} |
74 |
|
} else { |
75 |
1 |
LOGGER.warn("User [{}] has no email defined. Email will not been sent to that user.", reference); |
76 |
|
} |
77 |
|
|
78 |
17 |
return address; |
79 |
|
} |
80 |
|
} |