📄 jameshost.java
字号:
* @param username String representation of an email address * @param mailbox String representation of a mailbox name. * @return true if unsubscribe completes successfully */ public boolean unsubscribe( String userName, String mailboxName ) throws MailboxException, AccessControlException { Assert.isTrue( Assert.ON && userName != null && mailboxName != null && userName.length() > 0 && mailboxName.length() > 0 ); String absoluteName = getAbsoluteMailboxName( userName, mailboxName ); ACLMailbox mailbox = getAbsoluteMailbox( userName, absoluteName ); mailbox.unsubscribe( userName ); releaseMailbox( userName, mailbox ); return true; } /** * Returns a string giving the status of a mailbox on requested criteria. * Currently defined staus items are: * MESSAGES - Nummber of messages in mailbox * RECENT - Number of messages with \Recent flag set * UIDNEXT - The UID that will be assigned to the next message entering * the mailbox * UIDVALIDITY - The current UIDValidity value for the mailbox * UNSEEN - The number of messages which do not have the \Seen flag set. * * @param username String non-empty email address of requester * @param mailboxName String name of a mailbox (no wildcards allowed). * @param dataItems Vector of one or more Strings each of a single * status item. * @return String consisting of space seperated pairs: * dataItem-space-number. * @throws AccessControlException if the user does not have at least * lookup rights to the mailbox requested. * @throws MailboxException if the mailboxName does not exist locally. */ public String getMailboxStatus( String username, String mailboxName, List dataItems ) throws MailboxException, AccessControlException { String absoluteName = getAbsoluteMailboxName( username, mailboxName ); ACLMailbox mailbox = null; FolderRecord record = null; Iterator it = dataItems.iterator(); String response = null; // Has a folder with this name ever been created? if ( !recordRep.containsRecord( absoluteName ) ) { throw new MailboxException( "Mailbox: " + absoluteName + " has never been created.", MailboxException.NOT_LOCAL ); } else { record = recordRep.retrieve( absoluteName ); if ( record.isDeleted() ) { throw new MailboxException( "Mailbox has been deleted", MailboxException.LOCAL_BUT_DELETED ); } else if ( openMailboxes.contains( absoluteName ) ) { response = new String(); mailbox = openMailboxes.getMailbox( absoluteName ); if ( !mailbox.hasLookupRights( username ) ) { throw new AccessControlException( "No lookup rights." ); } while ( it.hasNext() ) { String dataItem = (String) it.next(); if ( dataItem.equalsIgnoreCase( "MESSAGES" ) ) { response += "MESSAGES " + mailbox.getExists(); } else if ( dataItem.equalsIgnoreCase( "RECENT" ) ) { response += "RECENT " + mailbox.getRecent(); } else if ( dataItem.equalsIgnoreCase( "UIDNEXT" ) ) { response += "UIDNEXT " + mailbox.getNextUID(); } else if ( dataItem.equalsIgnoreCase( "UIDVALIDITY" ) ) { response += "UIDVALIDITY " + mailbox.getUIDValidity(); } else if ( dataItem.equalsIgnoreCase( "UNSEEN" ) ) { response += "UNSEEN " + mailbox.getUnseen( username ); } if ( it.hasNext() ) { response += " "; } } return response; } else { if ( !record.hasLookupRights( username ) ) { throw new AccessControlException( "No lookup rights." ); } response = new String(); while ( it.hasNext() ) { String dataItem = (String) it.next(); if ( dataItem.equalsIgnoreCase( "MESSAGES" ) ) { response += "MESSAGES" + " " + record.getExists(); } else if ( dataItem.equalsIgnoreCase( "RECENT" ) ) { response += "RECENT" + " " + record.getRecent(); } else if ( dataItem.equalsIgnoreCase( "UIDNEXT" ) ) { response += "UIDNEXT" + " " + (record.getHighestUid() + 1); } else if ( dataItem.equalsIgnoreCase( "UIDVALIDITY" ) ) { response += "UIDVALIDITY" + " " + record.getUidValidity(); } else if ( dataItem.equalsIgnoreCase( "UNSEEN" ) ) { response += "UNSEEN" + " " + record.getUnseen( username ); } if ( it.hasNext() ) { response += " "; } } return response; } } } /** * Convert a user-based full mailbox name into a server absolute name. * If the fullMailboxName begins with the namespace token, * return as-is. * If not, need to resolve the Mailbox name for this user. * Example: * <br> Convert "INBOX" for user "Fred.Flinstone" into * absolute name: "#user.Fred.Flintstone.INBOX" * * @return String of absoluteName, null if not valid selection */ private String getAbsoluteMailboxName( String user, String fullMailboxName ) { // First decode the mailbox name as an Atom / String. if ( fullMailboxName.startsWith( NAMESPACE_TOKEN ) ) { return fullMailboxName; } else { if ( fullMailboxName.length() == 0 ) { return USER_NAMESPACE_PREFIX + HIERARCHY_SEPARATOR + user; } else { return USER_NAMESPACE_PREFIX + HIERARCHY_SEPARATOR + user + HIERARCHY_SEPARATOR + fullMailboxName; } } } /** * Convert a server absolute name into a user-aware mailbox name. * If the absolute name starts with #user.<username>. * remove this section. * Otherwise, return as-is. * * @return user-aware mailbox name */ private String getUserAwareMailboxName( String user, String absoluteName ) { String userPrefix = USER_NAMESPACE_PREFIX + HIERARCHY_SEPARATOR + user + HIERARCHY_SEPARATOR; String response; if ( absoluteName.startsWith( userPrefix ) ) { response = absoluteName.substring( userPrefix.length() ); } else { response = absoluteName; } return response; } /** * Return the file-system path to a given absoluteName mailbox. * * @param absoluteName the user-independent name of the mailbox * @param owner string name of owner of mailbox */ String getPath( String absoluteName ) { Assert.isTrue( Assert.ON && absoluteName.startsWith( NAMESPACE_TOKEN ) ); // Remove the leading '#' and replace Hierarchy separators with file separators. String filePath = absoluteName.substring( NAMESPACE_TOKEN.length() ); filePath = filePath.replace( HIERARCHY_SEPARATOR_CHAR, File.separatorChar ); return rootPath + filePath; } public boolean createPrivateMailAccount( String user ) { Assert.isTrue( Assert.ON && user != null && user.length() > 0 ); String userRootName = getAbsoluteMailboxName( user, "" ); String userInboxName = getAbsoluteMailboxName( user, "INBOX" ); SimpleFolderRecord userRootRecord = new SimpleFolderRecord( user, userRootName ); SimpleFolderRecord userInboxRecord = new SimpleFolderRecord( user, userInboxName ); ACLMailbox userRootFolder = new FileMailbox(); ACLMailbox userInbox = new FileMailbox(); try { setupLogger( userRootFolder ); userRootFolder.configure( conf ); userRootFolder.contextualize( context ); userRootFolder.compose( compMgr ); userRootFolder.prepareMailbox( user, userRootName, user, recordRep.nextUIDValidity() ); setupLogger( userInbox ); userInbox.configure( conf ); userInbox.contextualize( context ); userInbox.compose( compMgr ); userInbox.prepareMailbox( user, userInboxName, user, recordRep.nextUIDValidity() ); userRootFolder.initialize(); userRootFolder.setNotSelectableByAnyone( true ); userInbox.initialize(); userInbox.setRights( user, MailServer.MDA, "lrswi" ); } catch ( Exception e ) { getLogger().error( "Exception creating new account ", e ); return false; } userInboxRecord.initialize(); userInboxRecord.setUidValidity( userInbox.getUIDValidity() ); userInboxRecord.setHighestUid( userInbox.getNextUID() - 1 ); userInboxRecord.setLookupRights( userInbox.getUsersWithLookupRights() ); userInboxRecord.setReadRights( userInbox.getUsersWithReadRights() ); userInboxRecord.setNotSelectableByAnyone( userInbox.isNotSelectableByAnyone() ); userRootRecord.initialize(); userRootRecord.setLookupRights( userRootFolder.getUsersWithLookupRights() ); userRootRecord.setReadRights( userRootFolder.getUsersWithReadRights() ); userRootRecord.setNotSelectableByAnyone( userRootFolder.isNotSelectableByAnyone() ); recordRep.store( userRootRecord ); recordRep.store( userInboxRecord ); userRootFolder = null; userInbox = null; return true; } private static final class OpenMailboxes { private Map _mailboxes = new HashMap(); boolean contains( String absoluteName ) { return _mailboxes.containsKey( absoluteName ); } private OpenMailbox getOpen( String absoluteName ) { return (OpenMailbox)_mailboxes.get( absoluteName ); } void addMailbox( String absoluteName, ACLMailbox mailbox ) { OpenMailbox openMailbox = new OpenMailbox( mailbox ); _mailboxes.put( absoluteName, openMailbox ); } void removeMailbox( String absoluteName ) { _mailboxes.remove( absoluteName ); } ACLMailbox getMailbox( String absoluteName ) { return getOpen( absoluteName ).getMailbox(); } int addReference( String absoluteName ) { return getOpen( absoluteName ).addReference(); } int removeReference( String absoluteName ) { return getOpen( absoluteName ).removeReference(); } int getReferenceCount( String absoluteName ) { OpenMailbox openMailbox = getOpen( absoluteName ); if ( openMailbox == null ) { return 0; } else { return openMailbox.getReferenceCount(); } } } private static final class OpenMailbox { private ACLMailbox _mailbox; private int _referenceCount; OpenMailbox( ACLMailbox mailbox ) { _mailbox = mailbox; _referenceCount = 1; } ACLMailbox getMailbox() { return _mailbox; } int getReferenceCount() { return _referenceCount; } int addReference() { return ++_referenceCount; } int removeReference() { return --_referenceCount; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -