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: package org.columba.mail.gui.composer.command;
019:
020: import java.util.Arrays;
021: import java.util.Collections;
022: import java.util.Iterator;
023: import java.util.LinkedList;
024:
025: import org.columba.api.command.ICommandReference;
026: import org.columba.mail.composer.MessageBuilderHelper;
027: import org.columba.mail.config.AccountItem;
028: import org.columba.mail.config.MailConfig;
029: import org.columba.mail.folder.IMailbox;
030: import org.columba.ristretto.message.Address;
031: import org.columba.ristretto.message.BasicHeader;
032: import org.columba.ristretto.message.Header;
033:
034: /**
035: * Reply to All senders.
036: *
037: * @author fdietz
038: */
039: public class ReplyToAllCommand extends ReplyCommand {
040: protected final String[] headerfields = new String[] { "Subject",
041: "From", "To", "Cc", "Reply-To", "Message-ID",
042: "In-Reply-To", "References" };
043:
044: /**
045: * Constructor for ReplyToAllCommand.
046: *
047: * @param frameMediator
048: * @param references
049: */
050: public ReplyToAllCommand(ICommandReference reference) {
051: super (reference);
052: }
053:
054: protected void initHeader(IMailbox folder, Object[] uids)
055: throws Exception {
056: // get headerfields
057: Header header = folder.getHeaderFields(uids[0], headerfields);
058:
059: // From which account is this mail?
060: Integer accountUid = (Integer) folder.getAttribute(uids[0],
061: "columba.accountuid");
062: AccountItem accountItem = MessageBuilderHelper
063: .getAccountItem(accountUid);
064: Address accountAddress = null;
065: if (accountItem != null)
066: accountAddress = MailConfig.getInstance().getAccountList()
067: .uidGet(accountUid.intValue()).getIdentity()
068: .getAddress();
069:
070: BasicHeader rfcHeader = new BasicHeader(header);
071:
072: // set subject
073: model.setSubject(MessageBuilderHelper
074: .createReplySubject(rfcHeader.getSubject()));
075:
076: LinkedList toList = new LinkedList();
077: toList.addAll(Arrays.asList(rfcHeader.getReplyTo()));
078: toList.add(rfcHeader.getFrom());
079: toList.addAll(Arrays.asList(rfcHeader.getTo()));
080:
081: // bug #997560 (fdietz): CC: should be in Cc:, instead of To:
082: //toList.addAll(Arrays.asList(rfcHeader.getCc()));
083:
084: // remove duplicates
085: Collections.sort(toList);
086:
087: Iterator it = toList.iterator();
088: Address last = (Address) it.next();
089:
090: while (it.hasNext()) {
091: Address act = (Address) it.next();
092:
093: // Remove duplicates or the mail address from the receiver account
094: if (last.equals(act)
095: || (accountAddress != null && accountAddress
096: .equals(act))) {
097: it.remove();
098: } else {
099: last = act;
100: }
101: }
102:
103: Address[] to = (Address[]) toList.toArray(new Address[] {});
104:
105: // Add addresses to the addressbook
106: MessageBuilderHelper.addAddressesToAddressbook(to);
107: model.setTo(to);
108:
109: // bug #997560 (fdietz): CC: should be in Cc:, instead of To:
110: model.setCc(rfcHeader.getCc());
111:
112: // create In-Reply-To:, References: headerfields
113: MessageBuilderHelper
114: .createMailingListHeaderItems(header, model);
115:
116: // select the account this mail was received from
117: model.setAccountItem(accountItem);
118: }
119: }
|