01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //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: * Reply to mailinglist.
30: * <p>
31: * Uses the X-BeenThere: headerfield to determine the To: address
32: *
33: * @author fdizet
34: */
35: public class ReplyToMailingListCommand extends ReplyCommand {
36: protected final String[] headerfields = new String[] { "Subject",
37: "From", "To", "Reply-To", "Message-ID", "In-Reply-To",
38: "References", "X-Beenthere", "X-BeenThere" };
39:
40: /**
41: * Constructor for ReplyToMailingListCommand.
42: *
43: * @param frameMediator
44: * @param references
45: */
46: public ReplyToMailingListCommand(ICommandReference reference) {
47: super (reference);
48: }
49:
50: protected void initHeader(IMailbox folder, Object[] uids)
51: throws Exception {
52: // get headerfields
53: Header header = folder.getHeaderFields(uids[0], headerfields);
54:
55: BasicHeader rfcHeader = new BasicHeader(header);
56:
57: // set subject
58: model.setSubject(MessageBuilderHelper
59: .createReplySubject(rfcHeader.getSubject()));
60:
61: // Use reply-to field if given, else use from
62: Address to = rfcHeader.getBeenThere();
63:
64: if (to == null) {
65: Address[] replyTo = rfcHeader.getReplyTo();
66:
67: if (replyTo.length > 0) {
68: to = replyTo[0];
69: }
70: }
71:
72: if (to == null) {
73: to = rfcHeader.getFrom();
74: }
75:
76: MessageBuilderHelper
77: .addAddressesToAddressbook(new Address[] { to });
78: model.setTo(new Address[] { to });
79:
80: // create In-Reply-To:, References: headerfields
81: MessageBuilderHelper
82: .createMailingListHeaderItems(header, model);
83:
84: // select the account this mail was received from
85: Integer accountUid = (Integer) folder.getAttribute(uids[0],
86: "columba.accountuid");
87: AccountItem accountItem = MessageBuilderHelper
88: .getAccountItem(accountUid);
89: model.setAccountItem(accountItem);
90: }
91: }
|