View Javadoc

1   /**
2    *
3    * Copyright 2003-2005 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  
18  package org.apache.geronimo.javamail.store.pop3;
19  
20  /**
21   * Provides concrete implementations of
22   * org.apache.geronimo.javamail.store.pop3.POP3Command objects representing the
23   * POP3 commands defined in rfc 1939
24   * 
25   * @link http://www.faqs.org/rfcs/rfc1939.html
26   * @version $Rev: 432884 $ $Date: 2006-08-19 14:53:20 -0700 (Sat, 19 Aug 2006) $
27   */
28  public final class POP3CommandFactory implements POP3Constants {
29  
30      public static POP3Command getCOMMAND_USER(final String user) {
31          return new POP3Command() {
32              public String getCommand() {
33                  return "USER" + SPACE + user + CRLF;
34              }
35  
36              public boolean isMultiLineResponse() {
37                  return false;
38              }
39          };
40      }
41  
42      public static POP3Command getCOMMAND_PASS(final String passwd) {
43          return new POP3Command() {
44              public String getCommand() {
45                  return "PASS" + SPACE + passwd + CRLF;
46              }
47  
48              public boolean isMultiLineResponse() {
49                  return false;
50              }
51          };
52      }
53  
54      public static POP3Command getCOMMAND_QUIT() {
55          return new POP3Command() {
56              public String getCommand() {
57                  return "QUIT" + CRLF;
58              }
59  
60              public boolean isMultiLineResponse() {
61                  return false;
62              }
63          };
64      }
65  
66      public static POP3Command getCOMMAND_NOOP() {
67          return new POP3Command() {
68              public String getCommand() {
69                  return "NOOP" + CRLF;
70              }
71  
72              public boolean isMultiLineResponse() {
73                  return false;
74              }
75          };
76      }
77  
78      public static POP3Command getCOMMAND_STAT() {
79          return new POP3Command() {
80              public String getCommand() {
81                  return "STAT" + CRLF;
82              }
83  
84              public boolean isMultiLineResponse() {
85                  return false;
86              }
87          };
88      }
89  
90      public static POP3Command getCOMMAND_LIST() {
91          return getCOMMAND_LIST(-1);
92      }
93  
94      public static POP3Command getCOMMAND_LIST(final int msgNo) {
95          return new POP3Command() {
96              public String getCommand() {
97                  if (msgNo > 0) {
98                      return "LIST" + SPACE + msgNo + CRLF;
99                  } else {
100                     return "LIST" + CRLF;
101                 }
102             }
103 
104             /**
105              * If a msg num is specified then the the message details will be on
106              * the first line for ex. +OK 3 4520
107              * 
108              * if no msgnum is specified then all the msg details are return in
109              * a multiline format for ex. +OK 2 messages 1 456 2 46456 ..... n
110              * 366
111              */
112             public boolean isMultiLineResponse() {
113                 return (msgNo < 0);
114             }
115         };
116     }
117 
118     public static POP3Command getCOMMAND_RETR(final int msgNo) {
119         return new POP3Command() {
120             public String getCommand() {
121                 return "RETR" + SPACE + msgNo + CRLF;
122             }
123 
124             public boolean isMultiLineResponse() {
125                 return true;
126             }
127         };
128     }
129 
130     public static POP3Command getCOMMAND_DELE(final int msgNo) {
131         return new POP3Command() {
132             public String getCommand() {
133                 return "DELE" + SPACE + msgNo + CRLF;
134             }
135 
136             public boolean isMultiLineResponse() {
137                 return false;
138             }
139         };
140     }
141 
142     public static POP3Command getCOMMAND_REST(final int msgNo) {
143         return new POP3Command() {
144             public String getCommand() {
145                 return "REST" + SPACE + msgNo + CRLF;
146             }
147 
148             public boolean isMultiLineResponse() {
149                 return false;
150             }
151         };
152     }
153 
154     public static POP3Command getCOMMAND_TOP(final int msgNo, final int numLines) {
155         return new POP3Command() {
156             public String getCommand() {
157                 return "TOP" + SPACE + msgNo + SPACE + numLines + CRLF;
158             }
159 
160             public boolean isMultiLineResponse() {
161                 return true;
162             }
163         };
164     }
165 
166     public static POP3Command getCOMMAND_UIDL() {
167         return getCOMMAND_UIDL(-1);
168     }
169 
170     public static POP3Command getCOMMAND_UIDL(final int msgNo) {
171         return new POP3Command() {
172             public String getCommand() {
173                 if (msgNo > 0) {
174                     return "UIDL" + SPACE + msgNo + CRLF;
175                 } else {
176                     return "UIDL" + CRLF;
177                 }
178             }
179 
180             public boolean isMultiLineResponse() {
181                 return true;
182             }
183         };
184     }
185 
186 }