KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > filter > plugins > AddressbookFilter


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.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 JavaDoc uid) throws Exception JavaDoc {
51         Header header = ((IMailbox) folder).getHeaderFields(uid,
52                 new String JavaDoc[] { "From" });
53         String JavaDoc from = header.get("From");
54
55         Address address = null;
56         try {
57             address = AddressParser.parseAddress(from);
58         } catch (Exception JavaDoc 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.getCollectedAddresses();
73         String JavaDoc contactId = contactFacade.findByEmailAddress(contactFolder.getId(), address.getMailAddress());
74         if ( contactId != null ) return true;
75         
76         return false;
77     }
78
79     /**
80      * @see org.columba.core.filter.AbstractFilter#setUp(org.columba.mail.filter.FilterCriteria)
81      */

82     public void setUp(IFilterCriteria f) {
83
84     }
85 }
Popular Tags