01: package org.columba.mail.gui.util;
02:
03: import java.io.ByteArrayInputStream;
04: import java.io.InputStream;
05:
06: import org.columba.core.command.CommandProcessor;
07: import org.columba.core.io.DiskIO;
08: import org.columba.core.io.StreamUtils;
09: import org.columba.mail.command.MailFolderCommandReference;
10: import org.columba.mail.folder.IMailFolder;
11: import org.columba.mail.folder.command.AddMessageCommand;
12:
13: /**
14: * Create welcome message.
15: *
16: * @author fdietz
17: */
18: public class WelcomeMessage {
19:
20: private static String createMessage(String to, String accountUid)
21: throws Exception {
22: StringBuffer buf = new StringBuffer();
23: buf.append("Subject: Welcome to Columba\r\n");
24: buf.append("From: columba-users@lists.sourceforge.net\r\n");
25: buf.append("To: " + to + "\r\n");
26: buf.append("\r\n");
27:
28: InputStream is = DiskIO
29: .getResourceStream("org/columba/mail/welcome_message_body.txt");
30: String body = StreamUtils.readCharacterStream(is).toString();
31: buf.append(body);
32:
33: return buf.toString();
34: }
35:
36: /**
37: * Create welcome message and add it to folder.
38: *
39: * @param folder selected folder (usually this is inbox)
40: * @param to user's email address
41: * @param accountUid account id
42: * @throws Exception
43: */
44: public static void addWelcomeMessage(IMailFolder folder, String to,
45: String accountUid) throws Exception {
46: if (folder == null)
47: throw new IllegalArgumentException("folder == null");
48: if (to == null || to.length() == 0)
49: throw new IllegalArgumentException("to == nllu");
50: if (accountUid == null)
51: throw new IllegalArgumentException("account uid == null");
52:
53: // create message
54: String message = createMessage(to, accountUid);
55:
56: // convert to inputstream
57: InputStream is = new ByteArrayInputStream(message
58: .getBytes("UTF-8"));
59:
60: // add to folder
61: CommandProcessor.getInstance().addOp(
62: new AddMessageCommand(new MailFolderCommandReference(
63: folder), is));
64: }
65:
66: }
|