KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Arrays JavaDoc;
21 import java.util.Collections JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.LinkedList JavaDoc;
24
25 import org.columba.api.command.ICommandReference;
26 import org.columba.mail.composer.MessageBuilderHelper;
27 import org.columba.mail.config.AccountItem;
28 import org.columba.mail.config.MailConfig;
29 import org.columba.mail.folder.IMailbox;
30 import org.columba.ristretto.message.Address;
31 import org.columba.ristretto.message.BasicHeader;
32 import org.columba.ristretto.message.Header;
33
34
35 /**
36  * Reply to All senders.
37  *
38  * @author fdietz
39  */

40 public class ReplyToAllCommand extends ReplyCommand {
41     protected final String JavaDoc[] headerfields = new String JavaDoc[] {
42             "Subject", "From", "To", "Cc", "Reply-To", "Message-ID",
43             "In-Reply-To", "References"
44         };
45
46     /**
47      * Constructor for ReplyToAllCommand.
48      *
49      * @param frameMediator
50      * @param references
51      */

52     public ReplyToAllCommand(ICommandReference reference) {
53         super(reference);
54     }
55
56     protected void initHeader(IMailbox folder, Object JavaDoc[] uids)
57         throws Exception JavaDoc {
58         // get headerfields
59
Header header = folder.getHeaderFields(uids[0], headerfields);
60
61         // From which account is this mail?
62
Integer JavaDoc accountUid = (Integer JavaDoc) folder.getAttribute(uids[0], "columba.accountuid");
63         AccountItem accountItem = MessageBuilderHelper.getAccountItem(accountUid);
64         Address accountAddress = null;
65         if ( accountItem != null)
66             accountAddress = MailConfig.getInstance().getAccountList().uidGet(accountUid.intValue()).getIdentity().getAddress();
67         
68         BasicHeader rfcHeader = new BasicHeader(header);
69
70         // set subject
71
model.setSubject(MessageBuilderHelper.createReplySubject(
72                 rfcHeader.getSubject()));
73
74         LinkedList JavaDoc toList = new LinkedList JavaDoc();
75         toList.addAll(Arrays.asList(rfcHeader.getReplyTo()));
76         toList.add(rfcHeader.getFrom());
77         toList.addAll(Arrays.asList(rfcHeader.getTo()));
78         
79         // bug #997560 (fdietz): CC: should be in Cc:, instead of To:
80
//toList.addAll(Arrays.asList(rfcHeader.getCc()));
81

82         // remove duplicates
83
Collections.sort(toList);
84
85         Iterator JavaDoc it = toList.iterator();
86         Address last = (Address) it.next();
87
88         while (it.hasNext()) {
89             Address act = (Address) it.next();
90
91             // Remove duplicates or the mail address from the receiver account
92
if (last.equals(act) || (accountAddress != null && accountAddress.equals(act)) ) {
93                 it.remove();
94             } else {
95                 last = act;
96             }
97         }
98
99         Address[] to = (Address[]) toList.toArray(new Address[] { });
100
101         // Add addresses to the addressbook
102
MessageBuilderHelper.addAddressesToAddressbook(to);
103         model.setTo(to);
104         
105         // bug #997560 (fdietz): CC: should be in Cc:, instead of To:
106
model.setCc(rfcHeader.getCc());
107
108         // create In-Reply-To:, References: headerfields
109
MessageBuilderHelper.createMailingListHeaderItems(header, model);
110
111         // select the account this mail was received from
112
model.setAccountItem(accountItem);
113     }
114 }
115
Popular Tags