KickJava   Java API By Example, From Geeks To Geeks.

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


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.gui.composer.command;
19
20 import java.io.InputStream JavaDoc;
21
22 import org.columba.api.command.ICommandReference;
23 import org.columba.api.command.IWorkerStatusController;
24 import org.columba.mail.command.MailFolderCommandReference;
25 import org.columba.mail.folder.IMailbox;
26 import org.columba.mail.gui.composer.ComposerModel;
27 import org.columba.ristretto.message.InputStreamMimePart;
28 import org.columba.ristretto.message.MimeHeader;
29 import org.columba.ristretto.message.MimeType;
30
31 /**
32  * Reply to message, while keeping the original message as attachment. In
33  * comparison to quoting the bodytext inline.
34  *
35  * @author fdietz
36  */

37 public class ReplyAsAttachmentCommand extends ReplyCommand {
38
39     /**
40      * Constructor for ReplyCommand.
41      *
42      * @param frameMediator
43      * @param references
44      */

45     public ReplyAsAttachmentCommand(ICommandReference reference) {
46         super(reference);
47     }
48
49     public void execute(IWorkerStatusController worker) throws Exception JavaDoc {
50         // create composer model
51
model = new ComposerModel();
52
53         // get selected folder
54
IMailbox folder = (IMailbox) ((MailFolderCommandReference) getReference())
55                 .getSourceFolder();
56
57         // get first selected message
58
Object JavaDoc[] uids = ((MailFolderCommandReference) getReference()).getUids();
59
60         // ->set source reference in composermodel
61
// when replying this is the original sender's message
62
// you selected and replied to
63
MailFolderCommandReference ref = new MailFolderCommandReference(folder, uids);
64         model.setSourceReference(ref);
65
66         // setup to, references and account
67
initHeader(folder, uids);
68
69         // initialize MimeHeader as RFC822-compliant-message
70
MimeHeader mimeHeader = new MimeHeader();
71         mimeHeader.setMimeType(new MimeType("message", "rfc822"));
72         mimeHeader.setContentDescription((String JavaDoc)folder.getAttribute(uids[0],"columba.subject"));
73
74         // add mimepart to model
75

76         InputStream JavaDoc messageSourceStream = folder
77                 .getMessageSourceStream(uids[0]);
78         model.addMimePart(new InputStreamMimePart(mimeHeader,
79                 messageSourceStream));
80         messageSourceStream.close();
81     }
82 }
Popular Tags