View Javadoc

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  
21  
22  package org.apache.james.smtpserver;
23  
24  
25  import org.apache.james.util.watchdog.Watchdog;
26  import org.apache.mailet.Mail;
27  
28  import java.io.IOException;
29  import java.io.InputStream;
30  import java.util.Map;
31  
32  /**
33   * All the handlers access this interface to communicate with
34   * SMTPHandler object
35   */
36  
37  public interface SMTPSession {
38  
39      // Keys used to store/lookup data in the internal state hash map
40      public final static String MESG_FAILED = "MESG_FAILED";   // Message failed flag
41      public final static String SENDER = "SENDER_ADDRESS";     // Sender's email address
42      public final static String RCPT_LIST = "RCPT_LIST";   // The message recipients
43      public final static String CURRENT_HELO_MODE = "CURRENT_HELO_MODE"; // HELO or EHLO
44      public final static String CURRENT_HELO_NAME = "CURRENT_HELO_NAME"; 
45      public static final Object CURRENT_RECIPIENT = "CURRENT_RECIPIENT"; // Current recipient
46  
47      /**
48       * Writes response string to the client
49       *
50       * @param respString String that needs to send to the client
51       */
52      void writeResponse(String respString);
53  
54      /**
55       * Reads a line of characters off the command line.
56       *
57       * @return the trimmed input line
58       * @throws IOException if an exception is generated reading in the input characters
59       */
60      String readCommandLine() throws IOException;
61  
62  
63      /**
64       * Returns ResponseBuffer, this optimizes the unecessary creation of resources
65       * by each handler object
66       *
67       * @return responseBuffer
68       */
69      StringBuffer getResponseBuffer();
70  
71      /**
72       * Clears the response buffer, returning the String of characters in the buffer.
73       *
74       * @return the data in the response buffer
75       */
76      String clearResponseBuffer();
77  
78      /**
79       * Returns Inputstream for handling messages and commands
80       *
81       * @return InputStream object
82       */
83      InputStream getInputStream();
84  
85      /**
86       * Returns currently process command name
87       *
88       * @return current command name
89       */
90      String getCommandName();
91  
92      /**
93       * Returns currently process command argument
94       *
95       * @return current command argument
96       */
97      String getCommandArgument();
98  
99      /**
100      * Returns Mail object for message handlers to process
101      *
102      * @return Mail object
103      */
104     Mail getMail();
105 
106     /**
107      * Sets the MailImpl object for further processing
108      *
109      * @param mail MailImpl object
110      */
111     void setMail(Mail mail);
112 
113     /**
114      * Returns host name of the client
115      *
116      * @return hostname of the client
117      */
118     String getRemoteHost();
119 
120     /**
121      * Returns host ip address of the client
122      *
123      * @return host ip address of the client
124      */
125     String getRemoteIPAddress();
126 
127     /**
128      * this makes the message to be dropped inprotocol
129      *
130      */
131     void abortMessage();
132 
133     /**
134      * this makes the session to close
135      *
136      */
137     void endSession();
138 
139     /**
140      * Returns the session status
141      *
142      * @return if the session is open or closed
143      */
144     boolean isSessionEnded();
145 
146     /**
147      * Returns Map that consists of the state of the SMTPSession per mail
148      *
149      * @return map of the current SMTPSession state per mail
150      */
151     Map getState();
152 
153     /**
154      * Resets message-specific, but not authenticated user, state.
155      *
156      */
157     void resetState();
158 
159     /**
160      * Returns SMTPHandler service wide configuration
161      *
162      * @return SMTPHandlerConfigurationData
163      */
164     SMTPHandlerConfigurationData getConfigurationData();
165 
166     /**
167      * Returns whether Relaying is allowed or not
168      *
169      * @return the relaying status
170      */
171     boolean isRelayingAllowed();
172     
173     /**
174      * Set if reallying is allowed
175      * 
176      * @param relayingAllowed
177      */
178     void setRelayingAllowed(boolean relayingAllowed);
179 
180     /**
181      * Returns whether Authentication is required or not
182      *
183      * @return authentication required or not
184      */
185     boolean isAuthRequired();
186     
187     /**
188      * Returns whether remote server needs to send HELO/EHLO
189      *
190      * @return HELO/EHLO required or not
191      */
192     boolean useHeloEhloEnforcement();
193 
194     /**
195      * Returns the user name associated with this SMTP interaction.
196      *
197      * @return the user name
198      */
199     String getUser();
200 
201     /**
202      * Sets the user name associated with this SMTP interaction.
203      *
204      * @param user the user name
205      */
206     void setUser(String user);
207 
208     /**
209      * Returns Watchdog object used for handling timeout
210      *
211      * @return Watchdog object
212      */
213     Watchdog getWatchdog();
214 
215     /**
216      * Returns the SMTP session id
217      *
218      * @return SMTP session id
219      */
220     String getSessionID();
221     
222     /**
223      * Returns the recipient count
224      * 
225      * @return recipient count
226      */
227     int getRcptCount();
228 
229     /**
230      * Set to true if the handlerprocessing should be stopped
231      * 
232      * @param b true or false
233      */
234     void setStopHandlerProcessing(boolean b);
235     
236     /**
237      * Return if handlerprocessing should be stopped
238      * 
239      * @return true or false
240      */
241     boolean getStopHandlerProcessing();
242     
243     
244     /**
245      * Reset the Connection state
246      */
247     void resetConnectionState();
248     
249     /**
250      * Returns Map that consists of the state of the SMTPSession per connection
251      *
252      * @return map of the current SMTPSession state per connection
253      */
254     Map getConnectionState();
255 
256 }
257