1 package org.columba.mail.parser; 19 20 import java.util.Iterator ; 21 import java.util.List ; 22 import java.util.Vector ; 23 24 import org.columba.addressbook.facade.IContactFacade; 25 import org.columba.addressbook.facade.IContactItem; 26 import org.columba.addressbook.facade.IFolder; 27 import org.columba.addressbook.facade.IFolderFacade; 28 import org.columba.addressbook.facade.IGroupItem; 29 import org.columba.addressbook.facade.IHeaderItem; 30 import org.columba.api.exception.ServiceNotFoundException; 31 import org.columba.mail.connector.ServiceConnector; 32 33 38 public class ListBuilder { 39 40 private static IContactItem retrieveContactItem(String name) { 41 42 try { 43 IContactFacade facade = ServiceConnector.getContactFacade(); 44 IFolderFacade folderFacade = ServiceConnector.getFolderFacade(); 45 List <IFolder> list = folderFacade.getAllFolders(); 46 Iterator <IFolder> it = list.iterator(); 47 while (it.hasNext()) { 48 IFolder folder = it.next(); 49 String id = facade.findByName(folder.getId(), name); 50 if (id != null) { 51 IContactItem contactItem = facade.getContactItem(folder 52 .getId(), id); 53 return contactItem; 54 } 55 } 56 } catch (ServiceNotFoundException e) { 57 e.printStackTrace(); 58 } 59 60 return null; 61 } 62 63 67 private static IGroupItem retrieveGroupItem(String name) { 68 69 try { 70 IContactFacade facade = ServiceConnector.getContactFacade(); 71 IFolderFacade folderFacade = ServiceConnector.getFolderFacade(); 72 List <IFolder> list = folderFacade.getAllFolders(); 73 Iterator <IFolder> it = list.iterator(); 74 while (it.hasNext()) { 75 IFolder folder = it.next(); 76 List <IGroupItem> groupList = facade 77 .getAllGroups(folder.getId()); 78 Iterator <IGroupItem> groupIt = groupList.iterator(); 79 while (groupIt.hasNext()) { 80 IGroupItem groupItem = groupIt.next(); 81 if (name.equals(groupItem.getName())) 82 return groupItem; 83 } 84 } 85 } catch (ServiceNotFoundException e) { 86 e.printStackTrace(); 87 } 88 89 return null; 90 } 91 92 100 public static List <String > createFlatList(List <String > list) { 101 if (list == null) 102 throw new IllegalArgumentException ("list == null"); 103 104 List <String > result = new Vector <String >(); 105 106 Iterator <String > it = list.iterator(); 107 while (it.hasNext()) { 108 String str = it.next(); 109 110 str = str.trim(); 112 113 IContactItem contactItem = retrieveContactItem(str); 114 if (contactItem != null) { 115 result.add(contactItem.getEmailAddress()); 117 } else { 118 120 IGroupItem groupItem = retrieveGroupItem(str); 121 if (groupItem != null) { 122 123 List <IContactItem> contactItemList = groupItem 124 .getContacts(); 125 126 Iterator <IContactItem> it2 = contactItemList.iterator(); 127 while (it2.hasNext()) { 128 IContactItem i = it2.next(); 129 String address = i.getEmailAddress(); 130 131 if (address == null) { 132 continue; 133 } 134 135 result.add(address); 136 } 137 } else { 138 result.add(str); 139 } 140 } 141 } 142 143 return result; 144 } 145 146 154 public static List <String > createStringListFromItemList( 155 List <IHeaderItem> list) { 156 List <String > result = new Vector <String >(); 157 158 for (Iterator it = list.iterator(); it.hasNext();) { 159 IHeaderItem item = (IHeaderItem) it.next(); 160 result.add(item.getName()); 161 } 162 163 return result; 164 } 165 } | Popular Tags |