Coverage Report - com.jcabi.email.Protocol
 
Classes in this File Line Coverage Branch Coverage Complexity
Protocol
N/A
N/A
1
Protocol$SMTP
100%
5/5
N/A
1
Protocol$SMTPS
0%
0/5
N/A
1
 
 1  
 /**
 2  
  * Copyright (c) 2014-2015, jcabi.com
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met: 1) Redistributions of source code must retain the above
 8  
  * copyright notice, this list of conditions and the following
 9  
  * disclaimer. 2) Redistributions in binary form must reproduce the above
 10  
  * copyright notice, this list of conditions and the following
 11  
  * disclaimer in the documentation and/or other materials provided
 12  
  * with the distribution. 3) Neither the name of the jcabi.com nor
 13  
  * the names of its contributors may be used to endorse or promote
 14  
  * products derived from this software without specific prior written
 15  
  * permission.
 16  
  *
 17  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 19  
  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 20  
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 21  
  * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 22  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 24  
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 26  
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 28  
  * OF THE POSSIBILITY OF SUCH DAMAGE.
 29  
  */
 30  
 package com.jcabi.email;
 31  
 
 32  
 import com.google.common.collect.ImmutableMap;
 33  
 import com.jcabi.aspects.Immutable;
 34  
 import java.util.Map;
 35  
 import javax.net.ssl.SSLSocketFactory;
 36  
 
 37  
 /**
 38  
  * Mail network protocol.
 39  
  * @author Piotr Kotlicki (piotr.kotlicki@gmail.com)
 40  
  * @version $Id: fe5482cea5fe77981378867f24b34632fbc1a486 $
 41  
  * @since 1.0
 42  
  */
 43  
 @Immutable
 44  
 public interface Protocol {
 45  
 
 46  
     /**
 47  
      * Guarantee of access for protocol.
 48  
      * @return Entry parameters.
 49  
      */
 50  
     Map<String, String> entries();
 51  
 
 52  
     /**
 53  
      * SNMP protocol.
 54  
      */
 55  
     final class SMTP implements Protocol {
 56  
         /**
 57  
          * SMTP host.
 58  
          */
 59  
         private final transient String host;
 60  
 
 61  
         /**
 62  
          * SMTP port.
 63  
          */
 64  
         private final transient int port;
 65  
 
 66  
         /**
 67  
          * Public ctor.
 68  
          * @param hst SMTP Host
 69  
          * @param prt SMTP Port
 70  
          */
 71  1
         public SMTP(final String hst, final int prt) {
 72  1
             this.host = hst;
 73  1
             this.port = prt;
 74  1
         }
 75  
 
 76  
         @Override
 77  
         public Map<String, String> entries() {
 78  1
             return new ImmutableMap.Builder<String, String>()
 79  
                 .put("mail.smtp.auth", Boolean.TRUE.toString())
 80  
                 .put("mail.smtp.host", this.host)
 81  
                 .put("mail.smtp.port", Integer.toString(this.port))
 82  
                 .build();
 83  
         }
 84  
     }
 85  
 
 86  
     /**
 87  
      * SMTPS protocol.
 88  
      */
 89  
     final class SMTPS implements Protocol {
 90  
         /**
 91  
          * SMTPS host.
 92  
          */
 93  
         private final transient String host;
 94  
 
 95  
         /**
 96  
          * SMTPS port.
 97  
          */
 98  
         private final transient int port;
 99  
 
 100  
         /**
 101  
          * Public ctor.
 102  
          * @param hst SMTPS Host
 103  
          * @param prt SMTPS Port
 104  
          */
 105  0
         public SMTPS(final String hst, final int prt) {
 106  0
             this.host = hst;
 107  0
             this.port = prt;
 108  0
         }
 109  
 
 110  
         @Override
 111  
         public Map<String, String> entries() {
 112  0
             return new ImmutableMap.Builder<String, String>()
 113  
                 .putAll(new Protocol.SMTP(this.host, this.port).entries())
 114  
                 .put(
 115  
                     "mail.smtp.ssl.checkserveridentity",
 116  
                     Boolean.TRUE.toString()
 117  
                 ).put(
 118  
                     "mail.smtp.socketFactory.class",
 119  
                     SSLSocketFactory.class.getName()
 120  
                 ).put(
 121  
                     "mail.smtp.socketFactory.port",
 122  
                     Integer.toString(this.port)
 123  
                 ).put("mail.smtp.socketFactory.fallback", "false").build();
 124  
         }
 125  
     }
 126  
 }