1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.mail.internal.factory.message

File MessageMimeMessageFactory.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
3
1
1
76
25
2
0.67
3
1
2

Classes

Class Line # Actions
MessageMimeMessageFactory 63 3 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 3 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.message;
21   
22    import java.util.Map;
23   
24    import javax.inject.Named;
25    import javax.inject.Singleton;
26    import javax.mail.MessagingException;
27    import javax.mail.internet.MimeMessage;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.mail.ExtendedMimeMessage;
31    import org.xwiki.mail.internal.factory.AbstractMimeMessageFactory;
32   
33    /**
34    * This factory is useful when used by another MimeMessageFactory which delegates the creation of MimeMessages
35    * to another MimeMessageFactory, such as with a UserAndGroup Iterator MimeMessageFactory. For example:
36    *
37    * <code>
38    * {{velocity}}
39    * ## Create a mime message, the way you like it, adding any part you like, without recipient.
40    * #set ($message = $services.mailsender.createMessage('localhost@xwiki.org', null, 'SendMimeMessageToGroup'))
41    * #set ($discard = $message.addPart('text/plain', 'text content'))
42    *
43    * ## Use the mime message cloning factory as message factory to duplicate the created message
44    * #set ($parameters = {'hint' : 'message', 'source' : $message})
45    *
46    * #set ($source = {'groups' : [$services.model.createDocumentReference('', 'XWiki', 'XWikiAllGroup')]})
47    *
48    * #set ($messages = $services.mailsender.createMessages('usersandgroups', $source, $parameters))
49    * #set ($result = $services.mailsender.send($messages, 'database'))
50    * {{/velocity}}
51    * </code>
52    *
53    * Since 7.4.1, messages generated all receive the same MessageId header since these are clone of the same message.
54    * This behavior allow sending newsletter/mailing list message independently to many subscribers
55    * while allowing them to interact on the same thread of message, since all message are identified to be the same.
56    *
57    * @version $Id: c4dbf8fe971f4511bd77ae3385b833afc954da3d $
58    * @since 7.1M2
59    */
60    @Component
61    @Named("message")
62    @Singleton
 
63    public class MessageMimeMessageFactory extends AbstractMimeMessageFactory<MimeMessage>
64    {
 
65  5 toggle @Override
66    public MimeMessage createMessage(Object source, Map<String, Object> parameters)
67    throws MessagingException
68    {
69  5 if (!(source instanceof MimeMessage)) {
70  1 throw new MessagingException(
71    String.format("Failed to create mime message from source [%s]", source.getClass()));
72    }
73   
74  4 return new ExtendedMimeMessage((MimeMessage) source);
75    }
76    }