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.filter.plugins;
19:
20: import org.columba.addressbook.facade.IContactFacade;
21: import org.columba.addressbook.facade.IContactItem;
22: import org.columba.addressbook.facade.IFolderFacade;
23: import org.columba.api.exception.ServiceNotFoundException;
24: import org.columba.core.filter.AbstractFilter;
25: import org.columba.core.filter.FilterCriteria;
26: import org.columba.core.filter.IFilterCriteria;
27: import org.columba.core.folder.api.IFolder;
28: import org.columba.mail.connector.ServiceConnector;
29: import org.columba.mail.folder.IMailbox;
30: import org.columba.ristretto.message.Address;
31: import org.columba.ristretto.message.Header;
32: import org.columba.ristretto.parser.AddressParser;
33:
34: /**
35: * Check if sender is in all available addressbooks.
36: *
37: * @author fdietz
38: *
39: */
40: public class AddressbookFilter extends AbstractFilter {
41:
42: public AddressbookFilter() {
43:
44: }
45:
46: /**
47: * @see org.columba.core.filter.AbstractFilter#process(IFolder,
48: * java.lang.Object)
49: */
50: public boolean process(IFolder folder, Object uid) throws Exception {
51: Header header = ((IMailbox) folder).getHeaderFields(uid,
52: new String[] { "From" });
53: String from = header.get("From");
54:
55: Address address = null;
56: try {
57: address = AddressParser.parseAddress(from);
58: } catch (Exception ex) {
59: return false;
60: }
61:
62: IFolderFacade folderFacade = null;
63: IContactFacade contactFacade = null;
64: try {
65: folderFacade = ServiceConnector.getFolderFacade();
66: contactFacade = ServiceConnector.getContactFacade();
67: } catch (ServiceNotFoundException e) {
68: e.printStackTrace();
69: return false;
70: }
71:
72: org.columba.addressbook.facade.IFolder contactFolder = folderFacade
73: .getCollectedAddresses();
74: String contactId = contactFacade.findByEmailAddress(
75: contactFolder.getId(), address.getMailAddress());
76: if (contactId != null)
77: return true;
78:
79: return false;
80: }
81:
82: /**
83: * @see org.columba.core.filter.AbstractFilter#setUp(org.columba.mail.filter.FilterCriteria)
84: */
85: public void setUp(IFilterCriteria f) {
86:
87: }
88: }
|