1 package org.columba.mail.folder.command; 2 3 import java.net.URI ; 4 import java.net.URISyntaxException ; 5 import java.util.Hashtable ; 6 import java.util.Map.Entry; 7 import java.util.logging.Logger ; 8 9 import org.columba.api.command.IWorkerStatusController; 10 import org.columba.core.association.AssociationStore; 11 import org.columba.core.command.Command; 12 import org.columba.core.folder.api.IFolder; 13 import org.columba.mail.command.IMailFolderCommandReference; 14 import org.columba.mail.folder.IMailbox; 15 import org.columba.mail.folder.virtual.VirtualFolder; 16 import org.columba.mail.folder.virtual.VirtualHeader; 17 import org.columba.mail.message.IHeaderList; 18 19 public class TagMessageCommand extends Command { 20 21 public final static int ADD_TAG = 0; 22 23 public final static int REMOVE_TAG = 1; 24 25 private static final Logger LOG = Logger 26 .getLogger("org.columba.mail.folder.command.TagMessageCommand"); 27 28 private int type; 29 30 private String id; 31 32 public TagMessageCommand(IMailFolderCommandReference theReference, 33 int type, String id) { 34 super(theReference); 35 this.type = type; 36 this.id = id; 37 } 38 39 @Override 40 public void execute(IWorkerStatusController worker) throws Exception { 41 IMailFolderCommandReference r = (IMailFolderCommandReference) getReference(); 43 44 47 IMailbox srcFolder = (IMailbox) r.getSourceFolder(); 49 50 Hashtable <Object , IFolder> mails = new Hashtable <Object , IFolder>(); 51 52 if (srcFolder instanceof VirtualFolder) { 55 try { 57 58 IHeaderList hl = ((IMailbox) r.getSourceFolder()) 59 .getHeaderList(); 60 for (Object uid : r.getUids()) { 61 mails.put(((VirtualHeader) hl.get(uid)).getSrcUid(), 63 ((VirtualHeader) hl.get(uid)).getSrcFolder()); 64 } 65 } catch (Exception e) { 66 LOG.severe("Error getting header list from virtual folder"); 67 e.printStackTrace(); 68 } 69 } else { 70 for (Object uid : r.getUids()) { 71 mails.put(uid, r.getSourceFolder()); 72 } 73 } 74 75 if (type == ADD_TAG) { 76 for (Entry<Object , IFolder> entry : mails.entrySet()) { 77 AssociationStore.getInstance().addAssociation("tagging", id, 78 createURI(entry.getValue().getId(), entry.getKey()).toString()); 79 } 80 } else if (type == REMOVE_TAG) { 81 for (Entry<Object , IFolder> entry : mails.entrySet()) { 82 AssociationStore.getInstance().removeAssociation("tagging", id, 83 createURI(entry.getValue().getId(), entry.getKey()).toString()); 84 } 85 } 86 } 87 88 public static URI createURI(String folderId, Object messageId) { 90 URI uri = null; 91 try { 92 uri = new URI ("columba://org.columba.mail/" + folderId + "/" 93 + messageId); 94 } catch (URISyntaxException e) { 95 e.printStackTrace(); 96 } 97 return uri; 98 } 99 100 } 101 | Popular Tags |