001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018:
019: package org.columba.mail.gui.composer.command;
020:
021: import java.io.InputStream;
022:
023: import org.columba.api.command.ICommandReference;
024: import org.columba.api.command.IWorkerStatusController;
025: import org.columba.core.command.Command;
026: import org.columba.core.gui.frame.DefaultContainer;
027: import org.columba.mail.command.MailFolderCommandReference;
028: import org.columba.mail.composer.MessageBuilderHelper;
029: import org.columba.mail.folder.IMailbox;
030: import org.columba.mail.gui.composer.ComposerController;
031: import org.columba.mail.gui.composer.ComposerModel;
032: import org.columba.ristretto.message.BasicHeader;
033: import org.columba.ristretto.message.Header;
034: import org.columba.ristretto.message.InputStreamMimePart;
035: import org.columba.ristretto.message.MimeHeader;
036: import org.columba.ristretto.message.MimeType;
037:
038: /**
039: * Forward message as attachment.
040: *
041: * @author fdietz, tstich, karlpeder
042: */
043: public class ForwardCommand extends Command {
044:
045: protected ComposerController controller;
046:
047: protected ComposerModel model;
048:
049: /**
050: * Constructor for ForwardCommand.
051: *
052: * @param frameMediator
053: * @param references
054: */
055: public ForwardCommand(ICommandReference reference) {
056: super (reference);
057: }
058:
059: public void updateGUI() throws Exception {
060: // open composer frame
061: controller = new ComposerController();
062: new DefaultContainer(controller);
063:
064: // apply model
065: controller.setComposerModel(model);
066:
067: // model->view update
068: controller.updateComponents(true);
069: }
070:
071: public void execute(IWorkerStatusController worker)
072: throws Exception {
073: // get selected folder
074: IMailbox folder = (IMailbox) ((MailFolderCommandReference) getReference())
075: .getSourceFolder();
076:
077: // get first selected message
078: Object[] uids = ((MailFolderCommandReference) getReference())
079: .getUids();
080:
081: // get headerfields
082: Header header = folder.getHeaderFields(uids[0],
083: new String[] { "Subject" });
084:
085: // create composer model
086: model = new ComposerModel();
087:
088: // ->set source reference in composermodel
089: // when replying this is the original sender's message
090: // you selected and replied to
091: MailFolderCommandReference ref = new MailFolderCommandReference(
092: folder, uids);
093: model.setSourceReference(ref);
094:
095: // set subject
096: model.setSubject(MessageBuilderHelper
097: .createForwardSubject(new BasicHeader(header)
098: .getSubject()));
099:
100: // initialize MimeHeader as RFC822-compliant-message
101: MimeHeader mimeHeader = new MimeHeader();
102: mimeHeader.setMimeType(new MimeType("message", "rfc822"));
103: mimeHeader.setContentDescription((String) folder.getAttribute(
104: uids[0], "columba.subject"));
105:
106: // add mimepart to model
107:
108: InputStream messageSourceStream = folder
109: .getMessageSourceStream(uids[0]);
110: model.addMimePart(new InputStreamMimePart(mimeHeader,
111: messageSourceStream));
112: }
113:
114: /**
115: * Get composer model.
116: * <p>
117: * Needed for testcases.
118: *
119: * @return Returns the model.
120: */
121: public ComposerModel getModel() {
122: return model;
123: }
124: }
|