KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > composer > command > SaveMessageCommand


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.mail.gui.composer.command;
17
18 import java.io.InputStream JavaDoc;
19 import java.util.List JavaDoc;
20
21 import org.columba.api.command.ICommandReference;
22 import org.columba.api.command.IWorkerStatusController;
23 import org.columba.core.command.Command;
24 import org.columba.core.command.ProgressObservedInputStream;
25 import org.columba.core.command.Worker;
26 import org.columba.mail.command.ComposerCommandReference;
27 import org.columba.mail.composer.MessageBuilderHelper;
28 import org.columba.mail.composer.MessageComposer;
29 import org.columba.mail.composer.SendableMessage;
30 import org.columba.mail.folder.IMailbox;
31 import org.columba.mail.gui.composer.ComposerController;
32 import org.columba.mail.gui.composer.ComposerModel;
33 import org.columba.mail.util.MailResourceLoader;
34 import org.columba.ristretto.message.Address;
35 import org.columba.ristretto.parser.AddressParser;
36 import org.columba.ristretto.parser.ParserException;
37
38 /**
39  * @author freddy
40  */

41 public class SaveMessageCommand extends Command {
42     private IMailbox folder;
43
44     /**
45      * Constructor for SaveMessageCommand.
46      *
47      * @param reference
48      */

49     public SaveMessageCommand(ICommandReference reference) {
50         super(reference);
51     }
52
53     /**
54      * @param worker
55      * @throws Exception
56      * @see org.columba.api.command.Command#execute(Worker)
57      */

58     public void execute(IWorkerStatusController worker) throws Exception JavaDoc {
59         ComposerCommandReference r = (ComposerCommandReference) getReference();
60
61         ComposerController composerController = r.getComposerController();
62
63         SendableMessage message = (SendableMessage) r.getMessage();
64
65         if (message == null) {
66             message = new MessageComposer(((ComposerModel) composerController
67                     .getModel())).compose(worker, r.isAppendSignature());
68         }
69
70         folder = (IMailbox) r.getSourceFolder();
71
72         worker.setDisplayText(MailResourceLoader.getString("statusbar",
73                 "message", "save_message"));
74
75         InputStream JavaDoc sourceStream = new ProgressObservedInputStream(message
76                 .getSourceStream(), worker);
77         folder.addMessage(sourceStream, message.getHeader().getAttributes(),
78                 message.getHeader().getFlags());
79         sourceStream.close();
80
81         // Add all recipients to the collected addresses
82
List JavaDoc recipients = message.getRecipients();
83         if (recipients != null && recipients.size() > 0) {
84             Address[] addresses = new Address[recipients.size()];
85             for (int i = 0; i < recipients.size(); i++) {
86                 try {
87                     addresses[i] = AddressParser
88                             .parseAddress((String JavaDoc) recipients.get(i));
89                 } catch (ParserException e) {
90                     addresses[i] = addresses[i - 1];
91                 }
92             }
93
94             MessageBuilderHelper.addAddressesToAddressbook(addresses);
95         }
96     }
97 }
Popular Tags