1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.mail.internal.factory.usersandgroups

File AddressUserDataExtractor.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart8.png
56% of files have more coverage

Code metrics

2
10
3
1
80
42
5
0.5
3.33
3
1.67

Classes

Class Line # Actions
AddressUserDataExtractor 42 10 0% 5 4
0.7333333573.3%
 

Contributing tests

This file is covered by 10 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Extracts email addresses from User profiles.
37    *
38    * @version $Id: ef92de8c2d97cfdb04eb85767bdaab1bfe06a2fd $
39    * @since 6.4.2
40    * @since 7.0M2
41    */
 
42    public class AddressUserDataExtractor implements UserDataExtractor<Address>
43    {
44    private static final Logger LOGGER = LoggerFactory.getLogger(AddressUserDataExtractor.class);
45   
 
46  0 toggle @Override
47    public Address extractFromSuperadmin(DocumentReference reference)
48    {
49  0 return null;
50    }
51   
 
52  0 toggle @Override
53    public Address extractFromGuest(DocumentReference reference)
54    {
55  0 return null;
56    }
57   
 
58  17 toggle @Override
59    public Address extract(DocumentReference reference, XWikiDocument document, BaseObject userObject)
60    {
61  17 Address address = null;
62   
63    // Extract the email
64  17 String email = userObject.getStringValue("email");
65  17 if (!StringUtils.isBlank(email)) {
66    // Convert to an address
67  16 try {
68  16 address = InternetAddress.parse(email)[0];
69    } catch (AddressException e) {
70    // Invalid address, skip it, but log a warning!
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    }