1   /****************************************************************
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   ****************************************************************/
19  
20  package org.apache.mailet.base.test;
21  
22  import org.apache.mailet.MailetContext;
23  import org.apache.mailet.Mail;
24  import org.apache.mailet.MailAddress;
25  
26  import javax.mail.MessagingException;
27  import javax.mail.internet.MimeMessage;
28  import java.util.Collection;
29  import java.util.HashMap;
30  import java.util.Iterator;
31  
32  public class FakeMailContext implements MailetContext {
33      
34      HashMap attributes = new HashMap();
35  
36      public void bounce(Mail mail, String message) throws MessagingException {
37          // trivial implementation
38      }
39  
40      public void bounce(Mail mail, String message, MailAddress bouncer) throws MessagingException {
41          // trivial implementation
42      }
43  
44      public Collection getMailServers(String host) {
45          return null;  // trivial implementation
46      }
47  
48      public MailAddress getPostmaster() {
49          return null;  // trivial implementation
50      }
51  
52      public Object getAttribute(String name) {
53          return attributes.get(name);
54      }
55  
56      public Iterator getAttributeNames() {
57          return attributes.keySet().iterator();
58      }
59  
60      public int getMajorVersion() {
61          return 0;  // trivial implementation
62      }
63  
64      public int getMinorVersion() {
65          return 0;  // trivial implementation
66      }
67  
68      public String getServerInfo() {
69          return "Mock Server";
70      }
71  
72      public boolean isLocalServer(String serverName) {
73          return false;  // trivial implementation
74      }
75  
76      public boolean isLocalUser(String userAccount) {
77          return false;  // trivial implementation
78      }
79  
80      public boolean isLocalEmail(MailAddress mailAddress) {
81          return false;  // trivial implementation
82      }
83  
84      public void log(String message) {
85          System.out.println(message);
86      }
87  
88      public void log(String message, Throwable t) {
89          System.out.println(message);
90          t.printStackTrace(System.out);
91      }
92  
93      public void removeAttribute(String name) {
94          // trivial implementation
95      }
96  
97      public void sendMail(MimeMessage msg) throws MessagingException {
98          throw new UnsupportedOperationException("MOCKed method");
99      }
100 
101     public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg) throws MessagingException {
102         throw new UnsupportedOperationException("MOCKed method");
103     }
104 
105     public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg, String state) throws MessagingException {
106         throw new UnsupportedOperationException("MOCKed method");
107     }
108 
109     public void sendMail(Mail mail) throws MessagingException {
110         throw new UnsupportedOperationException("MOCKed method");
111     }
112 
113     public void setAttribute(String name, Object object) {
114         attributes.put(name,object);
115     }
116 
117     public void storeMail(MailAddress sender, MailAddress recipient, MimeMessage msg) throws MessagingException {
118         // trivial implementation
119     }
120 
121     public Iterator getSMTPHostAddresses(String domainName) {
122         return null;  // trivial implementation
123     }
124 }