1 package org.columba.mail.gui.util; 2 3 import java.io.ByteArrayInputStream ; 4 import java.io.InputStream ; 5 6 import org.columba.core.command.CommandProcessor; 7 import org.columba.core.io.DiskIO; 8 import org.columba.core.io.StreamUtils; 9 import org.columba.mail.command.MailFolderCommandReference; 10 import org.columba.mail.folder.IMailFolder; 11 import org.columba.mail.folder.command.AddMessageCommand; 12 13 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 44 public static void addWelcomeMessage(IMailFolder folder, String to, String accountUid) 45 throws Exception { 46 if ( folder == null) throw new IllegalArgumentException ("folder == null"); 47 if ( to == null || to.length() == 0) throw new IllegalArgumentException ("to == nllu"); 48 if ( accountUid == null ) throw new IllegalArgumentException ("account uid == null"); 49 50 51 String message = createMessage(to, accountUid); 53 54 InputStream is = new ByteArrayInputStream (message.getBytes("UTF-8")); 56 57 CommandProcessor.getInstance().addOp( 59 new AddMessageCommand(new MailFolderCommandReference( 60 folder), is)); 61 } 62 63 } 64 | Popular Tags |