KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.columba.api.command.ICommandReference;
21 import org.columba.mail.composer.MessageBuilderHelper;
22 import org.columba.mail.config.AccountItem;
23 import org.columba.mail.folder.IMailbox;
24 import org.columba.ristretto.message.Address;
25 import org.columba.ristretto.message.BasicHeader;
26 import org.columba.ristretto.message.Header;
27
28
29 /**
30  * Reply to mailinglist.
31  * <p>
32  * Uses the X-BeenThere: headerfield to determine the To: address
33  *
34  * @author fdizet
35  */

36 public class ReplyToMailingListCommand extends ReplyCommand {
37     protected final String JavaDoc[] headerfields = new String JavaDoc[] {
38             "Subject", "From", "To", "Reply-To", "Message-ID", "In-Reply-To",
39             "References", "X-Beenthere", "X-BeenThere"
40         };
41
42     /**
43      * Constructor for ReplyToMailingListCommand.
44      *
45      * @param frameMediator
46      * @param references
47      */

48     public ReplyToMailingListCommand(ICommandReference reference) {
49         super(reference);
50     }
51
52     protected void initHeader(IMailbox folder, Object JavaDoc[] uids)
53         throws Exception JavaDoc {
54         // get headerfields
55
Header header = folder.getHeaderFields(uids[0], headerfields);
56
57         BasicHeader rfcHeader = new BasicHeader(header);
58
59         // set subject
60
model.setSubject(MessageBuilderHelper.createReplySubject(
61                 rfcHeader.getSubject()));
62
63         // Use reply-to field if given, else use from
64
Address to = rfcHeader.getBeenThere();
65
66         if (to == null) {
67             Address[] replyTo = rfcHeader.getReplyTo();
68
69             if (replyTo.length > 0) {
70                 to = replyTo[0];
71             }
72         }
73
74         if (to == null) {
75             to = rfcHeader.getFrom();
76         }
77
78         MessageBuilderHelper.addAddressesToAddressbook(new Address[] { to });
79         model.setTo(new Address[] { to });
80
81         // create In-Reply-To:, References: headerfields
82
MessageBuilderHelper.createMailingListHeaderItems(header, model);
83
84         // select the account this mail was received from
85
Integer JavaDoc accountUid = (Integer JavaDoc) folder.getAttribute(uids[0],
86                 "columba.accountuid");
87         AccountItem accountItem = MessageBuilderHelper.getAccountItem(accountUid);
88         model.setAccountItem(accountItem);
89     }
90 }
91
Popular Tags