Reverse-merged /alfresco/BRANCHES/DEV/IMAP3:r14500,14521,14560,14563,14632

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14657 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2009-06-11 14:00:22 +00:00
parent 1a0c0dc758
commit cb7c4e6593
51 changed files with 2797 additions and 4727 deletions

View File

@@ -24,11 +24,27 @@
*/
package org.alfresco.repo.imap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.model.ContentModel;
import org.alfresco.model.ImapModel;
import org.alfresco.repo.imap.config.ImapConfigBean;
import org.alfresco.repo.imap.exception.AlfrescoImapFolderException;
import org.alfresco.repo.model.filefolder.FileFolderServiceImpl;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.model.FileNotFoundException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -37,6 +53,7 @@ import com.icegreen.greenmail.imap.ImapHostManager;
import com.icegreen.greenmail.store.FolderException;
import com.icegreen.greenmail.store.MailFolder;
import com.icegreen.greenmail.user.GreenMailUser;
import com.icegreen.greenmail.util.GreenMailUtil;
/**
* @author Mike Shavnev
@@ -46,8 +63,11 @@ public class AlfrescoImapHostManager implements ImapHostManager
private Log logger = LogFactory.getLog(AlfrescoImapHostManager.class);
private ImapService imapService;
private TransactionService transactionService;
private ServiceRegistry serviceRegistry;
private NodeService nodeService;
private FileFolderService fileFolderService;
private ImapHelper imapHelper;
/**
* Returns the hierarchy delimiter for mailboxes on this host.
@@ -70,14 +90,18 @@ public class AlfrescoImapHostManager implements ImapHostManager
*/
public Collection<MailFolder> listMailboxes(GreenMailUser user, String mailboxPattern) throws FolderException
{
try
mailboxPattern = GreenMailUtil.convertFromUtf7(mailboxPattern);
if (logger.isDebugEnabled())
{
return new ArrayList<MailFolder>(imapService.listMailboxes(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailboxPattern));
logger.debug("Listing mailboxes: mailboxPattern=" + mailboxPattern);
}
catch (Throwable e)
mailboxPattern = imapHelper.getMailPathInRepo(mailboxPattern);
if (logger.isDebugEnabled())
{
throw new FolderException(e.getMessage());
logger.debug("Listing mailboxes: mailboxPattern in alfresco=" + mailboxPattern);
}
return listMailboxes(user, mailboxPattern, false);
}
/**
@@ -92,14 +116,251 @@ public class AlfrescoImapHostManager implements ImapHostManager
*/
public Collection<MailFolder> listSubscribedMailboxes(GreenMailUser user, String mailboxPattern) throws FolderException
{
try
mailboxPattern = GreenMailUtil.convertFromUtf7(mailboxPattern);
if (logger.isDebugEnabled())
{
return new ArrayList<MailFolder>(imapService.listSubscribedMailboxes(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailboxPattern));
logger.debug("Listing subscribed mailboxes: mailboxPattern=" + mailboxPattern);
}
catch (Throwable e)
mailboxPattern = imapHelper.getMailPathInRepo(mailboxPattern);
if (logger.isDebugEnabled())
{
throw new FolderException(e.getMessage());
logger.debug("Listing subscribed mailboxes: mailboxPattern in alfresco=" + mailboxPattern);
}
return listMailboxes(user, mailboxPattern, true);
}
/**
* Depend on listSubscribed param, list Mailboxes or list subscribed Mailboxes
*/
private Collection<MailFolder> listMailboxes(GreenMailUser user, String mailboxPattern, boolean listSubscribed) throws FolderException
{
Collection<MailFolder> result = new LinkedList<MailFolder>();
Map<String, NodeRef> mountPoints = imapHelper.getMountPoints();
Map<String, ImapConfigBean> imapConfigs = imapHelper.getImapConfig();
NodeRef mountPoint;
// List mailboxes that are in mount points
for (String mountPointName : mountPoints.keySet())
{
mountPoint = mountPoints.get(mountPointName);
FileInfo mountPointFileInfo = imapHelper.getFileFolderService().getFileInfo(mountPoint);
NodeRef mountParent = imapHelper.getNodeService().getParentAssocs(mountPoint).get(0).getParentRef();
String viewMode = imapConfigs.get(mountPointName).getMode();
if (!mailboxPattern.equals("*"))
{
mountPoint = mountParent;
}
boolean isVirtualView = imapConfigs.get(mountPointName).getMode().equals(AlfrescoImapConst.MODE_VIRTUAL);
Collection<MailFolder> folders = listFolder(mountPoint, mountPoint, user, mailboxPattern, listSubscribed, isVirtualView);
if (folders != null)
{
for (MailFolder mailFolder : folders)
{
AlfrescoImapMailFolder folder = (AlfrescoImapMailFolder) mailFolder;
folder.setMountPointName(mountPointName);
folder.setViewMode(viewMode);
folder.setMountParent(mountParent);
}
result.addAll(folders);
}
// Add mount point to the result list
if (mailboxPattern.equals("*"))
{
if ((listSubscribed && isSubscribed(mountPointFileInfo, user.getLogin())) || (!listSubscribed))
{
result.add(new AlfrescoImapMailFolder(user.getQualifiedMailboxName(), mountPointFileInfo, mountPointName, viewMode, mountParent, mountPointName, imapHelper));
}
// \NoSelect
else if (listSubscribed && hasSubscribedChild(mountPointFileInfo, user.getLogin(), isVirtualView))
{
result.add(new AlfrescoImapMailFolder(user.getQualifiedMailboxName(), mountPointFileInfo, mountPointName, viewMode, mountParent, mountPointName, imapHelper,
false));
}
}
}
// List mailboxes that are in user IMAP Home
NodeRef root = imapHelper.getUserImapHomeRef(user.getLogin());
Collection<MailFolder> imapFolders = listFolder(root, root, user, mailboxPattern, listSubscribed, false);
if (imapFolders != null)
{
for (MailFolder mailFolder : imapFolders)
{
AlfrescoImapMailFolder folder = (AlfrescoImapMailFolder) mailFolder;
folder.setViewMode(AlfrescoImapConst.MODE_ARCHIVE);
folder.setMountParent(root);
}
result.addAll(imapFolders);
}
return result;
}
private Collection<MailFolder> listFolder(NodeRef mailboxRoot, NodeRef root, GreenMailUser user, String mailboxPattern, boolean listSubscribed, boolean isVirtualView)
throws FolderException
{
if (logger.isDebugEnabled())
{
logger.debug("Listing mailboxes: mailboxPattern=" + mailboxPattern);
}
int index = mailboxPattern.indexOf(AlfrescoImapConst.HIERARCHY_DELIMITER);
String name = null;
String remainName = null;
if (index < 0)
{
name = mailboxPattern;
}
else
{
name = mailboxPattern.substring(0, index);
remainName = mailboxPattern.substring(index + 1);
}
if (logger.isDebugEnabled())
{
logger.debug("Listing mailboxes: name=" + name);
}
if (index < 0)
{
if ("*".equals(name))
{
Collection<FileInfo> list = imapHelper.searchFolders(root, name, true, isVirtualView);
if (listSubscribed)
{
list = getSubscribed(list, user.getLogin());
}
if (list.size() > 0)
{
return createMailFolderList(user, list, mailboxRoot);
}
return null;
}
else if (name.endsWith("*"))
{
List<FileInfo> fullList = new LinkedList<FileInfo>();
List<FileInfo> list = imapHelper.searchFolders(root, name.replace('%', '*'), false, isVirtualView);
Collection<FileInfo> subscribedList = list;
if (listSubscribed)
{
subscribedList = getSubscribed(list, user.getLogin());
}
if (list.size() > 0)
{
fullList.addAll(subscribedList);
for (FileInfo fileInfo : list)
{
List<FileInfo> childList = imapHelper.searchFolders(fileInfo.getNodeRef(), "*", true, isVirtualView);
if (listSubscribed)
{
fullList.addAll(getSubscribed(childList, user.getLogin()));
}
else
{
fullList.addAll(childList);
}
}
return createMailFolderList(user, fullList, mailboxRoot);
}
return null;
}
else if ("%".equals(name))
{
List<FileInfo> list = imapHelper.searchFolders(root, "*", false, isVirtualView);
LinkedList<MailFolder> subscribedList = new LinkedList<MailFolder>();
if (listSubscribed)
{
for (FileInfo fileInfo : list)
{
if (isSubscribed(fileInfo, user.getLogin()))
{
// folderName, viewMode, mountPointName will be setted in listMailboxes() method
subscribedList.add(new AlfrescoImapMailFolder(user.getQualifiedMailboxName(), fileInfo, null, null, mailboxRoot, null, imapHelper));
}
// \NoSelect
else if (hasSubscribedChild(fileInfo, user.getLogin(), isVirtualView))
{
// folderName, viewMode, mountPointName will be setted in listMailboxes() method
subscribedList.add(new AlfrescoImapMailFolder(user.getQualifiedMailboxName(), fileInfo, null, null, mailboxRoot, null, imapHelper, false));
}
}
}
else
{
return createMailFolderList(user, list, mailboxRoot);
}
return subscribedList;
}
else if (name.contains("%") || name.contains("*"))
{
List<FileInfo> list = imapHelper.searchFolders(root, name.replace('%', '*'), false, isVirtualView);
Collection<FileInfo> subscribedList = list;
if (listSubscribed)
{
subscribedList = getSubscribed(list, user.getLogin());
}
if (subscribedList.size() > 0)
{
return createMailFolderList(user, subscribedList, mailboxRoot);
}
return null;
}
else
{
List<FileInfo> list = imapHelper.searchFolders(root, name, false, isVirtualView);
Collection<FileInfo> subscribedList = list;
if (listSubscribed)
{
subscribedList = getSubscribed(list, user.getLogin());
}
if (subscribedList.size() > 0)
{
return createMailFolderList(user, subscribedList, mailboxRoot);
}
return null;
}
}
// If (index != -1) this is not the last level
Collection<MailFolder> result = new LinkedList<MailFolder>();
List<FileInfo> list = imapHelper.searchFolders(root, name.replace('%', '*'), false, isVirtualView);
for (FileInfo folder : list)
{
Collection<MailFolder> childFolders = listFolder(mailboxRoot, folder.getNodeRef(), user, remainName, listSubscribed, isVirtualView);
if (childFolders != null)
{
result.addAll(childFolders);
}
}
if (result.isEmpty())
{
return null;
}
return result;
}
/**
@@ -114,16 +375,97 @@ public class AlfrescoImapHostManager implements ImapHostManager
* @throws com.icegreen.greenmail.store.FolderException if an existing folder with the new name.
* @throws AlfrescoImapFolderException if user does not have rights to create the new mailbox.
*/
public void renameMailbox(GreenMailUser user, String oldMailboxName, String newMailboxName) throws FolderException, AuthorizationException
{
try
oldMailboxName = GreenMailUtil.convertFromUtf7(oldMailboxName);
newMailboxName = GreenMailUtil.convertFromUtf7(newMailboxName);
if (logger.isDebugEnabled())
{
imapService.renameMailbox(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), oldMailboxName, newMailboxName);
logger.debug("Renaming folder: oldMailboxName=" + oldMailboxName + " newMailboxName=" + newMailboxName);
}
catch (Throwable e)
AlfrescoImapMailFolder sourceNode = (AlfrescoImapMailFolder) getFolder(user, GreenMailUtil.convertInUtf7(oldMailboxName));
NodeRef root = imapHelper.getMailboxRootRef(oldMailboxName, user.getLogin());
String mailboxRepoName = imapHelper.getMailPathInRepo(newMailboxName);
StringTokenizer tokenizer = new StringTokenizer(mailboxRepoName, String.valueOf(AlfrescoImapConst.HIERARCHY_DELIMITER));
NodeRef parentNodeRef = root;
while (tokenizer.hasMoreTokens())
{
throw new FolderException(e.getMessage());
String folderName = tokenizer.nextToken();
if (!tokenizer.hasMoreTokens())
{
try
{
if (oldMailboxName.equalsIgnoreCase(AlfrescoImapConst.INBOX_NAME))
{
// If you trying to rename INBOX
// - just copy it to another folder with new name
// and leave INBOX (with children) intact.
fileFolderService.copy(sourceNode.getFolderInfo().getNodeRef(), parentNodeRef, folderName);
List<FileInfo> itemsForRemove = fileFolderService.list(sourceNode.getFolderInfo().getNodeRef());
for (FileInfo fileInfo : itemsForRemove)
{
fileFolderService.delete(fileInfo.getNodeRef());
}
}
else
{
fileFolderService.move(sourceNode.getFolderInfo().getNodeRef(), parentNodeRef, folderName);
}
return;
}
catch (FileExistsException e)
{
throw new FolderException(FolderException.ALREADY_EXISTS_LOCALLY);
}
catch (FileNotFoundException e)
{
if (logger.isDebugEnabled())
{
logger.error(e);
}
}
}
else
{
List<FileInfo> folders = imapHelper.searchFolders(parentNodeRef, folderName, false, true);
if (folders.size() == 0)
{
AccessStatus status = imapHelper.hasPermission(parentNodeRef, PermissionService.WRITE);
if (status == AccessStatus.DENIED)
{
if (logger.isDebugEnabled())
{
logger.debug("Creating folder: Cant't create folder - Permission denied");
}
throw new AlfrescoImapFolderException(AlfrescoImapFolderException.PERMISSION_DENIED);
}
if (logger.isDebugEnabled())
{
logger.debug("Create mailBox: " + folderName);
}
FileFolderServiceImpl.makeFolders(fileFolderService, parentNodeRef, Arrays.asList(folderName), ContentModel.TYPE_FOLDER);
}
else
{
parentNodeRef = folders.get(0).getNodeRef();
if (logger.isDebugEnabled())
{
logger.debug("MailBox: " + folderName + " already exists");
}
}
}
}
}
/**
@@ -138,14 +480,58 @@ public class AlfrescoImapHostManager implements ImapHostManager
*/
public MailFolder createMailbox(GreenMailUser user, String mailboxName) throws AuthorizationException, FolderException
{
try
mailboxName = GreenMailUtil.convertFromUtf7(mailboxName);
if (logger.isDebugEnabled())
{
return imapService.createMailbox(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailboxName);
logger.debug("Creating folder: " + mailboxName);
}
catch (Throwable e)
NodeRef root = imapHelper.getMailboxRootRef(mailboxName, user.getLogin());
String mountPointName = imapHelper.getMountPointName(mailboxName);
String mailboxRepoNam = imapHelper.getMailPathInRepo(mailboxName);
StringTokenizer tokenizer = new StringTokenizer(mailboxRepoNam, String.valueOf(AlfrescoImapConst.HIERARCHY_DELIMITER));
NodeRef parentNodeRef = root;
while (tokenizer.hasMoreTokens())
{
throw new FolderException(e.getMessage());
String folderName = tokenizer.nextToken();
List<FileInfo> folders = imapHelper.searchFolders(parentNodeRef, folderName, false, true);
if (folders.size() == 0)
{
AccessStatus status = imapHelper.hasPermission(parentNodeRef, PermissionService.WRITE);
if (status == AccessStatus.DENIED)
{
if (logger.isDebugEnabled())
{
logger.debug("Creating folder: Cant't create folder - Permission denied");
}
throw new AlfrescoImapFolderException(AlfrescoImapFolderException.PERMISSION_DENIED);
}
if (logger.isDebugEnabled())
{
logger.debug("Create mailBox: " + mailboxName);
}
FileInfo mailFolder = FileFolderServiceImpl.makeFolders(fileFolderService, parentNodeRef, Arrays.asList(folderName), ContentModel.TYPE_FOLDER);
return new AlfrescoImapMailFolder(user.getQualifiedMailboxName(), mailFolder, folderName, imapHelper.getViewMode(mailboxName), root, mountPointName, imapHelper);
}
else
{
parentNodeRef = folders.get(0).getNodeRef();
if (logger.isDebugEnabled())
{
logger.debug("MailBox: " + folderName + " already exists");
}
}
}
throw new FolderException(FolderException.ALREADY_EXISTS_LOCALLY);
}
/**
@@ -158,13 +544,34 @@ public class AlfrescoImapHostManager implements ImapHostManager
*/
public void deleteMailbox(GreenMailUser user, String mailboxName) throws FolderException, AuthorizationException
{
try
AlfrescoImapMailFolder folder = (AlfrescoImapMailFolder) getFolder(user, mailboxName);
NodeRef nodeRef = folder.getFolderInfo().getNodeRef();
List<FileInfo> childFolders = imapHelper.searchFolders(nodeRef, "*", false, false);
if (childFolders.isEmpty())
{
imapService.deleteMailbox(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailboxName);
folder.signalDeletion();
// Delete child folders and messages
fileFolderService.delete(nodeRef);
}
catch (Throwable e)
else
{
throw new FolderException(e.getMessage());
if (folder.isSelectable())
{
// Delete all messages for this folder
// Don't delete subfolders and their messages
List<FileInfo> messages = imapHelper.searchFiles(nodeRef, "*", ImapModel.TYPE_IMAP_CONTENT, false);
for (FileInfo message : messages)
{
fileFolderService.delete(message.getNodeRef());
}
nodeService.addAspect(nodeRef, ImapModel.ASPECT_IMAP_FOLDER_NONSELECTABLE, null);
}
else
{
throw new FolderException(mailboxName + " - Can't delete a non-selectable store with children.");
}
}
}
@@ -179,22 +586,80 @@ public class AlfrescoImapHostManager implements ImapHostManager
*/
public MailFolder getFolder(GreenMailUser user, String mailboxName)
{
return imapService.getFolder(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailboxName);
mailboxName = GreenMailUtil.convertFromUtf7(mailboxName);
if (logger.isDebugEnabled())
{
logger.debug("Getting folder: " + mailboxName);
}
// If MailFolder object is used to obtain hierarchy delimiter by LIST command:
// Example:
// C: 2 list "" ""
// S: * LIST () "." ""
// S: 2 OK LIST completed.
if ("".equals(mailboxName))
{
if (logger.isDebugEnabled())
{
logger.debug("Request for the hierarchy delimiter");
}
return new AlfrescoImapMailFolder(user.getQualifiedMailboxName(), null, null, null, null, null, null);
}
NodeRef root = imapHelper.getMailboxRootRef(mailboxName, user.getLogin());
String mountPointName = imapHelper.getMountPointName(mailboxName);
String mailboxRepoName = imapHelper.getMailPathInRepo(mailboxName);
StringTokenizer tokenizer = new StringTokenizer(mailboxRepoName, String.valueOf(AlfrescoImapConst.HIERARCHY_DELIMITER));
int count = tokenizer.countTokens();
NodeRef nodeRef = root;
while (tokenizer.hasMoreTokens())
{
String t = tokenizer.nextToken();
if (logger.isDebugEnabled())
{
logger.debug("token=" + t);
}
count--;
List<FileInfo> list = imapHelper.searchFolders(nodeRef, t, false, true);
if (count == 0)
{
if (!list.isEmpty())
{
return new AlfrescoImapMailFolder(user.getQualifiedMailboxName(), list.get(0), list.get(0).getName(), imapHelper.getViewMode(mailboxName), root,
mountPointName, imapHelper);
}
else
{
return new AlfrescoImapMailFolder(user.getQualifiedMailboxName(), null, null, null, null, null, null);
}
}
else
{
if (!list.isEmpty())
{
nodeRef = list.get(0).getNodeRef();
}
else
{
return new AlfrescoImapMailFolder(user.getQualifiedMailboxName(), null, null, null, null, null, null);
}
}
}
throw new IllegalStateException("Error state");
}
/**
* Simply calls {@link #getFolder(GreenMailUser, String)}. <p/> Added to implement {@link ImapHostManager}.
*/
public MailFolder getFolder(final GreenMailUser user, final String mailboxName, boolean mustExist) throws FolderException
public MailFolder getFolder(GreenMailUser user, String mailboxName, boolean mustExist) throws FolderException
{
try
{
return getFolder(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailboxName);
}
catch (Throwable e)
{
throw new FolderException(e.getMessage());
}
return getFolder(user, mailboxName);
}
/**
@@ -205,14 +670,7 @@ public class AlfrescoImapHostManager implements ImapHostManager
*/
public MailFolder getInbox(GreenMailUser user) throws FolderException
{
try
{
return getFolder(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), AlfrescoImapConst.INBOX_NAME);
}
catch (Throwable e)
{
throw new FolderException(e.getMessage());
}
return getFolder(user, AlfrescoImapConst.INBOX_NAME);
}
/**
@@ -229,16 +687,39 @@ public class AlfrescoImapHostManager implements ImapHostManager
* @param user User making the request
* @param mailbox String representation of a mailbox name.
*/
public void subscribe(GreenMailUser user, String mailbox) throws FolderException
public void subscribe(final GreenMailUser user, final String mailbox) throws FolderException
{
try
if (logger.isDebugEnabled())
{
imapService.subscribe(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailbox);
}
catch (Throwable e)
{
throw new FolderException(e.getMessage());
logger.debug("Subscribing: " + mailbox);
}
AlfrescoImapMailFolder mailFolder = (AlfrescoImapMailFolder) getFolder(user, mailbox);
nodeService.addAspect(mailFolder.getFolderInfo().getNodeRef(), ImapModel.ASPECT_IMAP_FOLDER_SUBSCRIBED, null);
// This is a multiuser support. Commented due new requirements
// AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>()
// {
// public Void doWork() throws Exception
// {
// AlfrescoImapMailFolder mailFolder = (AlfrescoImapMailFolder) getFolder(user, mailbox);
// FileInfo fileInfo = mailFolder.getFolderInfo();
// if (fileInfo != null)
// {
// String subscribedList = (String) nodeService.getProperty(fileInfo.getNodeRef(), ImapModel.PROP_IMAP_FOLDER_SUBSCRIBED);
// if (subscribedList == null)
// {
// subscribedList = "";
// }
// subscribedList = subscribedList.replaceAll(imapHelper.formatUserEntry(user.getLogin()), "");
// subscribedList += imapHelper.formatUserEntry(user.getLogin());
// nodeService.setProperty(fileInfo.getNodeRef(), ImapModel.PROP_IMAP_FOLDER_SUBSCRIBED, subscribedList);
// }
// else
// {
// logger.debug("MailBox: " + mailbox + "doesn't exsist. Maybe it was deleted earlier.");
// }
// return null;
// }
// }, AuthenticationUtil.getSystemUserName());
}
/**
@@ -247,46 +728,137 @@ public class AlfrescoImapHostManager implements ImapHostManager
* @param user User making the request
* @param mailbox String representation of a mailbox name.
*/
public void unsubscribe(GreenMailUser user, String mailbox) throws FolderException
public void unsubscribe(final GreenMailUser user, final String mailbox) throws FolderException
{
try
if (logger.isDebugEnabled())
{
imapService.unsubscribe(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailbox);
}
catch (Throwable e)
{
throw new FolderException(e.getMessage());
logger.debug("Unsubscribing: " + mailbox);
}
AlfrescoImapMailFolder mailFolder = (AlfrescoImapMailFolder) getFolder(user, mailbox);
nodeService.removeAspect(mailFolder.getFolderInfo().getNodeRef(), ImapModel.ASPECT_IMAP_FOLDER_SUBSCRIBED);
// This is a multiuser support. Commented due new requirements
// AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>()
// {
// public Void doWork() throws Exception
// {
// AlfrescoImapMailFolder mailFolder = (AlfrescoImapMailFolder) getFolder(user, mailbox);
// if (mailFolder.getFolderInfo() != null)
// {
// FileInfo fileInfo = mailFolder.getFolderInfo();
// String subscribedList = (String) nodeService.getProperty(fileInfo.getNodeRef(), ImapModel.PROP_IMAP_FOLDER_SUBSCRIBED);
// if (subscribedList == null)
// {
// subscribedList = "";
// }
// subscribedList = subscribedList.replaceAll(imapHelper.formatUserEntry(user.getLogin()), "");
// nodeService.setProperty(fileInfo.getNodeRef(), ImapModel.PROP_IMAP_FOLDER_SUBSCRIBED, subscribedList);
// }
// else
// {
// logger.debug("MailBox: " + mailbox + " doesn't exsist. Maybe it was deleted earlier.");
// }
//
// return null;
// }
// }, AuthenticationUtil.getSystemUserName());
}
/**
* Not supported. Used by GreenMail class.
*/
public List<?> getAllMessages()
public List getAllMessages()
{
throw new UnsupportedOperationException();
}
private boolean isSubscribed(FileInfo fileInfo, String userName)
{
return nodeService.hasAspect(fileInfo.getNodeRef(), ImapModel.ASPECT_IMAP_FOLDER_SUBSCRIBED);
// This is a multiuser support. Commented due new requirements
// Map<QName, Serializable> properties = fileInfo.getProperties();
// String subscribedList = (String) properties.get(ImapModel.PROP_IMAP_FOLDER_SUBSCRIBED);
// if (subscribedList == null)
// {
// return false;
// }
// else
// {
// return subscribedList.contains(imapHelper.formatUserEntry(userName));
// }
}
private Collection<FileInfo> getSubscribed(Collection<FileInfo> list, String userName)
{
Collection<FileInfo> result = new LinkedList<FileInfo>();
for (FileInfo folderInfo : list)
{
if (isSubscribed(folderInfo, userName))
{
result.add(folderInfo);
}
}
return result;
}
private boolean hasSubscribedChild(FileInfo parent, String userName, boolean isVirtualView)
{
List<FileInfo> list = imapHelper.searchFolders(parent.getNodeRef(), "*", true, isVirtualView);
for (FileInfo fileInfo : list)
{
if (isSubscribed(fileInfo, userName))
{
return true;
}
}
return false;
}
private Collection<MailFolder> createMailFolderList(GreenMailUser user, Collection<FileInfo> list, NodeRef imapUserHomeRef)
{
Collection<MailFolder> result = new LinkedList<MailFolder>();
for (FileInfo folderInfo : list)
{
// folderName, viewMode, mountPointName will be setted in listSubscribedMailboxes() method
result.add(new AlfrescoImapMailFolder(user.getQualifiedMailboxName(), folderInfo, null, null, imapUserHomeRef, null, imapHelper));
}
return result;
}
// ----------------------Getters and Setters----------------------------
public ImapService getImapService()
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
return imapService;
this.serviceRegistry = serviceRegistry;
}
public void setImapService(ImapService imapService)
public ServiceRegistry getServiceRegistry()
{
this.imapService = imapService;
return serviceRegistry;
}
public TransactionService getTransactionService()
public void setNodeService(NodeService nodeService)
{
return transactionService;
this.nodeService = nodeService;
}
public void setTransactionService(TransactionService transactionService)
public void setFileFolderService(FileFolderService fileFolderService)
{
this.transactionService = transactionService;
this.fileFolderService = fileFolderService;
}
public void setImapHelper(ImapHelper imapHelper)
{
this.imapHelper = imapHelper;
}
}