mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged DEV/IMAP3 to HEAD
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14654 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -24,27 +24,11 @@
|
||||
*/
|
||||
package org.alfresco.repo.imap;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
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.alfresco.service.transaction.TransactionService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@@ -53,7 +37,6 @@ 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
|
||||
@@ -63,11 +46,8 @@ public class AlfrescoImapHostManager implements ImapHostManager
|
||||
|
||||
private Log logger = LogFactory.getLog(AlfrescoImapHostManager.class);
|
||||
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
private NodeService nodeService;
|
||||
private FileFolderService fileFolderService;
|
||||
private ImapHelper imapHelper;
|
||||
private ImapService imapService;
|
||||
private TransactionService transactionService;
|
||||
|
||||
/**
|
||||
* Returns the hierarchy delimiter for mailboxes on this host.
|
||||
@@ -90,18 +70,14 @@ public class AlfrescoImapHostManager implements ImapHostManager
|
||||
*/
|
||||
public Collection<MailFolder> listMailboxes(GreenMailUser user, String mailboxPattern) throws FolderException
|
||||
{
|
||||
mailboxPattern = GreenMailUtil.convertFromUtf7(mailboxPattern);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
try
|
||||
{
|
||||
logger.debug("Listing mailboxes: mailboxPattern=" + mailboxPattern);
|
||||
return new ArrayList<MailFolder>(imapService.listMailboxes(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailboxPattern));
|
||||
}
|
||||
mailboxPattern = imapHelper.getMailPathInRepo(mailboxPattern);
|
||||
if (logger.isDebugEnabled())
|
||||
catch (Throwable e)
|
||||
{
|
||||
logger.debug("Listing mailboxes: mailboxPattern in alfresco=" + mailboxPattern);
|
||||
throw new FolderException(e.getMessage());
|
||||
}
|
||||
return listMailboxes(user, mailboxPattern, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,251 +92,14 @@ public class AlfrescoImapHostManager implements ImapHostManager
|
||||
*/
|
||||
public Collection<MailFolder> listSubscribedMailboxes(GreenMailUser user, String mailboxPattern) throws FolderException
|
||||
{
|
||||
mailboxPattern = GreenMailUtil.convertFromUtf7(mailboxPattern);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
try
|
||||
{
|
||||
logger.debug("Listing subscribed mailboxes: mailboxPattern=" + mailboxPattern);
|
||||
return new ArrayList<MailFolder>(imapService.listSubscribedMailboxes(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailboxPattern));
|
||||
}
|
||||
mailboxPattern = imapHelper.getMailPathInRepo(mailboxPattern);
|
||||
if (logger.isDebugEnabled())
|
||||
catch (Throwable e)
|
||||
{
|
||||
logger.debug("Listing subscribed mailboxes: mailboxPattern in alfresco=" + mailboxPattern);
|
||||
throw new FolderException(e.getMessage());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,97 +114,16 @@ 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
|
||||
{
|
||||
oldMailboxName = GreenMailUtil.convertFromUtf7(oldMailboxName);
|
||||
newMailboxName = GreenMailUtil.convertFromUtf7(newMailboxName);
|
||||
if (logger.isDebugEnabled())
|
||||
try
|
||||
{
|
||||
logger.debug("Renaming folder: oldMailboxName=" + oldMailboxName + " newMailboxName=" + newMailboxName);
|
||||
imapService.renameMailbox(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), oldMailboxName, newMailboxName);
|
||||
}
|
||||
|
||||
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())
|
||||
catch (Throwable e)
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new FolderException(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -480,58 +138,14 @@ public class AlfrescoImapHostManager implements ImapHostManager
|
||||
*/
|
||||
public MailFolder createMailbox(GreenMailUser user, String mailboxName) throws AuthorizationException, FolderException
|
||||
{
|
||||
mailboxName = GreenMailUtil.convertFromUtf7(mailboxName);
|
||||
if (logger.isDebugEnabled())
|
||||
try
|
||||
{
|
||||
logger.debug("Creating folder: " + mailboxName);
|
||||
return imapService.createMailbox(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailboxName);
|
||||
}
|
||||
|
||||
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())
|
||||
catch (Throwable e)
|
||||
{
|
||||
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(e.getMessage());
|
||||
}
|
||||
|
||||
throw new FolderException(FolderException.ALREADY_EXISTS_LOCALLY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -544,34 +158,13 @@ public class AlfrescoImapHostManager implements ImapHostManager
|
||||
*/
|
||||
public void deleteMailbox(GreenMailUser user, String mailboxName) throws FolderException, AuthorizationException
|
||||
{
|
||||
AlfrescoImapMailFolder folder = (AlfrescoImapMailFolder) getFolder(user, mailboxName);
|
||||
NodeRef nodeRef = folder.getFolderInfo().getNodeRef();
|
||||
|
||||
List<FileInfo> childFolders = imapHelper.searchFolders(nodeRef, "*", false, false);
|
||||
|
||||
if (childFolders.isEmpty())
|
||||
try
|
||||
{
|
||||
folder.signalDeletion();
|
||||
// Delete child folders and messages
|
||||
fileFolderService.delete(nodeRef);
|
||||
imapService.deleteMailbox(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailboxName);
|
||||
}
|
||||
else
|
||||
catch (Throwable e)
|
||||
{
|
||||
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.");
|
||||
}
|
||||
throw new FolderException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,80 +179,22 @@ public class AlfrescoImapHostManager implements ImapHostManager
|
||||
*/
|
||||
public MailFolder getFolder(GreenMailUser user, String 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");
|
||||
return imapService.getFolder(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailboxName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply calls {@link #getFolder(GreenMailUser, String)}. <p/> Added to implement {@link ImapHostManager}.
|
||||
*/
|
||||
public MailFolder getFolder(GreenMailUser user, String mailboxName, boolean mustExist) throws FolderException
|
||||
public MailFolder getFolder(final GreenMailUser user, final String mailboxName, boolean mustExist) throws FolderException
|
||||
{
|
||||
return getFolder(user, mailboxName);
|
||||
try
|
||||
{
|
||||
return getFolder(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailboxName);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
throw new FolderException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -670,7 +205,14 @@ public class AlfrescoImapHostManager implements ImapHostManager
|
||||
*/
|
||||
public MailFolder getInbox(GreenMailUser user) throws FolderException
|
||||
{
|
||||
return getFolder(user, AlfrescoImapConst.INBOX_NAME);
|
||||
try
|
||||
{
|
||||
return getFolder(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), AlfrescoImapConst.INBOX_NAME);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
throw new FolderException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -687,39 +229,16 @@ public class AlfrescoImapHostManager implements ImapHostManager
|
||||
* @param user User making the request
|
||||
* @param mailbox String representation of a mailbox name.
|
||||
*/
|
||||
public void subscribe(final GreenMailUser user, final String mailbox) throws FolderException
|
||||
public void subscribe(GreenMailUser user, String mailbox) throws FolderException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
try
|
||||
{
|
||||
logger.debug("Subscribing: " + mailbox);
|
||||
imapService.subscribe(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailbox);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
throw new FolderException(e.getMessage());
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -728,137 +247,46 @@ public class AlfrescoImapHostManager implements ImapHostManager
|
||||
* @param user User making the request
|
||||
* @param mailbox String representation of a mailbox name.
|
||||
*/
|
||||
public void unsubscribe(final GreenMailUser user, final String mailbox) throws FolderException
|
||||
public void unsubscribe(GreenMailUser user, String mailbox) throws FolderException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
try
|
||||
{
|
||||
logger.debug("Unsubscribing: " + mailbox);
|
||||
imapService.unsubscribe(new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword()), mailbox);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
throw new FolderException(e.getMessage());
|
||||
}
|
||||
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 void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||
public ImapService getImapService()
|
||||
{
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
return imapService;
|
||||
}
|
||||
|
||||
public ServiceRegistry getServiceRegistry()
|
||||
public void setImapService(ImapService imapService)
|
||||
{
|
||||
return serviceRegistry;
|
||||
this.imapService = imapService;
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
public TransactionService getTransactionService()
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
return transactionService;
|
||||
}
|
||||
|
||||
public void setFileFolderService(FileFolderService fileFolderService)
|
||||
public void setTransactionService(TransactionService transactionService)
|
||||
{
|
||||
this.fileFolderService = fileFolderService;
|
||||
}
|
||||
|
||||
public void setImapHelper(ImapHelper imapHelper)
|
||||
{
|
||||
this.imapHelper = imapHelper;
|
||||
this.transactionService = transactionService;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user