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 java.util.Iterator; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import javax.mail.Address; |
26 |
|
import javax.mail.Message; |
27 |
|
import javax.mail.MessagingException; |
28 |
|
import javax.mail.internet.MimeMessage; |
29 |
|
|
30 |
|
import org.xwiki.context.Execution; |
31 |
|
import org.xwiki.mail.ExtendedMimeMessage; |
32 |
|
import org.xwiki.mail.MimeMessageFactory; |
33 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
@since |
42 |
|
|
|
|
| 91.7% |
Uncovered Elements: 2 (24) |
Complexity: 7 |
Complexity Density: 0.41 |
|
43 |
|
public class UsersAndGroupsMimeMessageIterator implements Iterator<MimeMessage>, Iterable<MimeMessage> |
44 |
|
{ |
45 |
|
private MimeMessageFactory<MimeMessage> factory; |
46 |
|
|
47 |
|
private Iterator<Address> addressIterator; |
48 |
|
|
49 |
|
private Map<String, Object> parameters; |
50 |
|
|
51 |
|
|
52 |
|
@param |
53 |
|
|
54 |
|
@param |
55 |
|
@param |
56 |
|
@param |
57 |
|
@link |
58 |
|
@param@link |
59 |
|
@throws |
60 |
|
|
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
62 |
4 |
public UsersAndGroupsMimeMessageIterator(Map<String, Object> source,... |
63 |
|
MimeMessageFactory<MimeMessage> factory, Map<String, Object> parameters, |
64 |
|
DocumentReferenceResolver<String> explicitDocumentReferenceResolver, Execution execution) |
65 |
|
throws MessagingException |
66 |
|
{ |
67 |
4 |
this.addressIterator = new AddressUserIterator(UsersAndGroupsSource.parse(source), |
68 |
|
explicitDocumentReferenceResolver, execution); |
69 |
4 |
this.factory = factory; |
70 |
4 |
this.parameters = parameters; |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
1 |
@Override... |
74 |
|
public Iterator<MimeMessage> iterator() |
75 |
|
{ |
76 |
1 |
return this; |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
7 |
@Override... |
80 |
|
public boolean hasNext() |
81 |
|
{ |
82 |
7 |
return this.addressIterator.hasNext(); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.27 |
|
85 |
5 |
@Override... |
86 |
|
public MimeMessage next() |
87 |
|
{ |
88 |
5 |
MimeMessage message; |
89 |
5 |
Address address = this.addressIterator.next(); |
90 |
|
|
91 |
5 |
try { |
92 |
5 |
Map<String, Object> factoryParameters = (Map<String, Object>) this.parameters.get("parameters"); |
93 |
5 |
message = this.factory.createMessage(this.parameters.get("source"), factoryParameters); |
94 |
4 |
message.addRecipient(Message.RecipientType.TO, address); |
95 |
|
|
96 |
|
|
97 |
4 |
String type = (String) this.parameters.get("type"); |
98 |
4 |
if (type != null) { |
99 |
2 |
ExtendedMimeMessage.wrap(message).setType(type); |
100 |
|
} |
101 |
|
} catch (MessagingException e) { |
102 |
1 |
throw new RuntimeException("Failed to create Mime Message for recipient " + address, e); |
103 |
|
} |
104 |
|
|
105 |
4 |
return message; |
106 |
|
} |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
108 |
0 |
@Override... |
109 |
|
public void remove() |
110 |
|
{ |
111 |
0 |
throw new UnsupportedOperationException("remove"); |
112 |
|
} |
113 |
|
} |