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.james.test.mock.mailet;
21
22 import java.io.Serializable;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.Date;
26 import java.util.HashMap;
27 import java.util.Iterator;
28
29 import javax.mail.MessagingException;
30 import javax.mail.internet.MimeMessage;
31
32 import org.apache.mailet.Mail;
33 import org.apache.mailet.MailAddress;
34
35 public class MockMail implements Mail {
36
37 private MimeMessage msg = null;
38
39 private Collection recipients = new ArrayList();
40
41 private String name = null;
42
43 private MailAddress sender = null;
44
45 private String state = null;
46
47 private String errorMessage;
48
49 private Date lastUpdated;
50
51 private HashMap attributes = new HashMap();
52
53 private static final long serialVersionUID = 1L;
54
55 public String getName() {
56 return name;
57 }
58
59 public void setName(String newName) {
60 this.name = newName;
61 }
62
63 public MimeMessage getMessage() throws MessagingException {
64 return msg;
65 }
66
67 public Collection getRecipients() {
68 return recipients;
69 }
70
71 public void setRecipients(Collection recipients) {
72 this.recipients = recipients;
73 }
74
75 public MailAddress getSender() {
76 return sender;
77 }
78
79 public String getState() {
80 return state;
81 }
82
83 public String getRemoteHost() {
84 throw new UnsupportedOperationException("Unimplemented mock service");
85 }
86
87 public String getRemoteAddr() {
88 throw new UnsupportedOperationException("Unimplemented mock service");
89 }
90
91 public String getErrorMessage() {
92 return errorMessage;
93 }
94
95 public void setErrorMessage(String msg) {
96 this.errorMessage = msg;
97 }
98
99 public void setMessage(MimeMessage message) {
100 this.msg = message;
101 }
102
103 public void setState(String state) {
104 this.state = state;
105 }
106
107 public Serializable getAttribute(String name) {
108 return (Serializable) attributes.get(name);
109 }
110
111 public Iterator getAttributeNames() {
112 return attributes.keySet().iterator();
113 }
114
115 public boolean hasAttributes() {
116 return !attributes.isEmpty();
117 }
118
119 public Serializable removeAttribute(String name) {
120 return (Serializable) attributes.remove(name);
121
122 }
123
124 public void removeAllAttributes() {
125 attributes.clear();
126 }
127
128 public Serializable setAttribute(String name, Serializable object) {
129
130 return (Serializable) attributes.put(name, object);
131 }
132
133 public long getMessageSize() throws MessagingException {
134 throw new UnsupportedOperationException("Unimplemented mock service");
135 }
136
137 public Date getLastUpdated() {
138 return lastUpdated;
139 }
140
141 public void setLastUpdated(Date lastUpdated) {
142 this.lastUpdated = lastUpdated;
143 }
144
145 }