001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.mail.gui.composer.command;
017:
018: import java.io.InputStream;
019: import java.util.List;
020:
021: import org.columba.api.command.ICommandReference;
022: import org.columba.api.command.IWorkerStatusController;
023: import org.columba.core.command.Command;
024: import org.columba.core.command.ProgressObservedInputStream;
025: import org.columba.core.command.Worker;
026: import org.columba.mail.command.ComposerCommandReference;
027: import org.columba.mail.composer.MessageBuilderHelper;
028: import org.columba.mail.composer.MessageComposer;
029: import org.columba.mail.composer.SendableMessage;
030: import org.columba.mail.folder.IMailbox;
031: import org.columba.mail.gui.composer.ComposerController;
032: import org.columba.mail.gui.composer.ComposerModel;
033: import org.columba.mail.util.MailResourceLoader;
034: import org.columba.ristretto.message.Address;
035: import org.columba.ristretto.parser.AddressParser;
036: import org.columba.ristretto.parser.ParserException;
037:
038: /**
039: * @author freddy
040: */
041: public class SaveMessageCommand extends Command {
042: private IMailbox folder;
043:
044: /**
045: * Constructor for SaveMessageCommand.
046: *
047: * @param reference
048: */
049: public SaveMessageCommand(ICommandReference reference) {
050: super (reference);
051: }
052:
053: /**
054: * @param worker
055: * @throws Exception
056: * @see org.columba.api.command.Command#execute(Worker)
057: */
058: public void execute(IWorkerStatusController worker)
059: throws Exception {
060: ComposerCommandReference r = (ComposerCommandReference) getReference();
061:
062: ComposerController composerController = r
063: .getComposerController();
064:
065: SendableMessage message = (SendableMessage) r.getMessage();
066:
067: if (message == null) {
068: message = new MessageComposer(
069: ((ComposerModel) composerController.getModel()))
070: .compose(worker, r.isAppendSignature());
071: }
072:
073: folder = (IMailbox) r.getSourceFolder();
074:
075: worker.setDisplayText(MailResourceLoader.getString("statusbar",
076: "message", "save_message"));
077:
078: InputStream sourceStream = new ProgressObservedInputStream(
079: message.getSourceStream(), worker);
080: folder.addMessage(sourceStream, message.getHeader()
081: .getAttributes(), message.getHeader().getFlags());
082: sourceStream.close();
083:
084: // Add all recipients to the collected addresses
085: List recipients = message.getRecipients();
086: if (recipients != null && recipients.size() > 0) {
087: Address[] addresses = new Address[recipients.size()];
088: for (int i = 0; i < recipients.size(); i++) {
089: try {
090: addresses[i] = AddressParser
091: .parseAddress((String) recipients.get(i));
092: } catch (ParserException e) {
093: addresses[i] = addresses[i - 1];
094: }
095: }
096:
097: MessageBuilderHelper.addAddressesToAddressbook(addresses);
098: }
099: }
100: }
|