1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.dexterim.msn.message;
20
21 import java.util.List;
22
23 import net.sf.dexterim.msn.MsnConnection;
24 import net.sf.dexterim.msn.util.SpecialCharacters;
25
26 /***
27 *@author Christoph Walcher
28 */
29 public class MimeMessageFactory extends MimeMessage {
30 private String account;
31 private String nick;
32 private String mimeType;
33 private String mimeVersion;
34 private String characterSet;
35 private boolean complete = false;
36 private String body;
37
38 /***
39 * Description of the Field
40 */
41 public final static String MSN_PROFILE = "text/x-msmsgsprofile;";
42
43 /***
44 * Description of the Field
45 */
46 public final static String MSN_MAIL_NOTIFICATION =
47 "text/x-msmsgsinitialemailnotification;";
48
49 /***
50 * Description of the Field
51 */
52 public final static String USER_TYPING = "text/x-msmsgscontrol;";
53
54 /***
55 * Description of the Field
56 */
57 public final static String USER_MESSAGE = "text/plain;";
58
59 /***
60 * Creates a new instance of MimeMessage
61 */
62 public MimeMessageFactory() {
63 }
64
65 /***
66 * Adds a Received Line to a Message. Return an instance of MsnMessage
67 *
68 *@param line The String line to be added to the Message
69 *@return Description of the Return Value
70 *@exception MessageFormatException Description of the Exception
71 */
72 public MsnMessage addLine(String line)
73 throws MessageFormatException {
74 try {
75 TokenizedLine tokenLine = new TokenizedLine(line);
76
77 account = tokenLine.getToken(1);
78 nick =
79 SpecialCharacters.getInstance().decode(tokenLine.getToken(2), true);
80 super.setRequiredByteInput(Integer.parseInt(tokenLine.getToken(3)));
81
82 return this;
83 } catch (Exception ex) {
84 throw new MessageFormatException(ex);
85 }
86 }
87
88 /***
89 * Gets the multipartMessage attribute of the MimeMessageFactory object
90 *
91 *@return The multipartMessage value
92 */
93 public boolean isMultipartMessage() {
94 return true;
95 }
96
97 /***
98 * Return true if MsnMessage does not require any further input. Is
99 * Completed will be called <b>after</b> the first addLine was called!
100 *
101 *@return The completed value
102 */
103 public boolean isCompleted() {
104 return complete;
105 }
106
107 /***
108 * Getter for property mimeType.
109 *
110 *@return Value of property mimeType.
111 */
112 public java.lang.String getMimeType() {
113 return mimeType;
114 }
115
116 /***
117 * Getter for property mimeVersion.
118 *
119 *@return Value of property mimeVersion.
120 */
121 public java.lang.String getMimeVersion() {
122 return mimeVersion;
123 }
124
125 /***
126 * Getter for property characterSet.
127 *
128 *@return Value of property characterSet.
129 */
130 public java.lang.String getCharacterSet() {
131 return characterSet;
132 }
133
134 /***
135 * Gets the messageCommand attribute of the MimeMessageFactory object
136 *
137 *@return The messageCommand value
138 */
139 public String getMessageCommand() {
140 return "MSG";
141 }
142
143 /***
144 * Adds a feature to the CharBlock attribute of the MimeMessageFactory
145 * object
146 *
147 *@param charBlock The feature to be added to the CharBlock attribute
148 *@return Description of the Return Value
149 *@exception MessageFormatException Description of the Exception
150 */
151 public MsnMessage addCharBlock(char[] charBlock)
152 throws MessageFormatException {
153 complete = true;
154
155 body = new String(charBlock);
156
157 java.util.List lineList = inspectBody(body);
158
159 if (mimeType != null) {
160 if ("Hotmail".equals(account) && "Hotmail".equals(nick)) {
161 if (MSN_MAIL_NOTIFICATION.equals(mimeType)) {
162 HotmailNotificationMessage message = new HotmailNotificationMessage();
163
164 message.processMessage(account, nick, lineList);
165
166 return message;
167 } else if (MSN_PROFILE.equals(mimeType)) {
168 HotmailProfileMessage message = new HotmailProfileMessage();
169
170 message.processMessage(account, nick, lineList);
171
172 return message;
173 }
174 } else if (USER_TYPING.equals(mimeType)) {
175 UserTypingMessage message = new UserTypingMessage();
176
177 message.processMessage(account, nick, lineList);
178
179 return message;
180 } else if (USER_MESSAGE.equals(mimeType)) {
181 UserMessage message = new UserMessage();
182
183 message.processMessage(account, nick, lineList);
184
185 return message;
186 }
187 }
188
189 return null;
190 }
191
192 /***
193 * Description of the Method
194 *
195 *@param body Description of the Parameter
196 *@return Description of the Return Value
197 *@exception MessageFormatException Description of the Exception
198 */
199 protected List inspectBody(String body) throws MessageFormatException {
200 try {
201 List retVal = new java.util.ArrayList();
202
203 java.io.BufferedReader reader =
204 new java.io.BufferedReader(new java.io.StringReader(body));
205
206 TokenizedLine line = new TokenizedLine(reader.readLine());
207
208 mimeVersion = line.getToken(1);
209
210 line = new TokenizedLine(reader.readLine());
211 mimeType = line.getToken(1);
212
213 if (line.getTokenCount() > 2) {
214 characterSet = line.getToken(2);
215 }
216
217 String stringLine = null;
218
219 while ((stringLine = reader.readLine()) != null) {
220 retVal.add(stringLine);
221 }
222
223 reader.close();
224
225 return retVal;
226 } catch (java.io.IOException ioex) {
227 throw new MessageFormatException(ioex);
228 }
229 }
230
231 /***
232 * Description of the Method
233 *
234 *@param account Description of the Parameter
235 *@param nick Description of the Parameter
236 *@param lineList Description of the Parameter
237 *@exception MessageFormatException Description of the Exception
238 */
239 public void processMessage(String account, String nick, List lineList) {
240 throw new UnsupportedOperationException();
241 }
242
243
244
245
246 public void process(MsnConnection connection) {
247
248
249 }
250 }