📄 jameshost.java
字号:
fr = new SimpleFolderRecord(user, subnewabsolutename); fr.setUidValidity( mmm.getUIDValidity() ); fr.setLookupRights( mmm.getUsersWithLookupRights() ); fr.setReadRights( mmm.getUsersWithReadRights() ); fr.setMarked( mmm.isMarked() ); fr.setNotSelectableByAnyone( mmm.isNotSelectableByAnyone() ); fr.setExists( mmm.getExists() ); fr.setRecent( mmm.getRecent() ); fr.setUnseenbyUser( mmm.getUnseenByUser() ); recordRep.store(fr); // Remove old entry from openMailboxes and create a new one this.openMailboxes.removeMailbox(suboldabsolutename); this.openMailboxes.addMailbox(subnewabsolutename,mmm); } else { // RENAME MAILBOX MAIN System.out.println("NEWMAILBOXNAME WILL BE "+newMailboxName); if (mmm.renameMailbox(user, newMailboxName)) { // THis is the new AbsoluteName with # and so on String absolutenewName = getAbsoluteMailboxName(user, newMailboxName); // Delete the old FolderRecord FolderRecord fr = recordRep.retrieve(oldAbsoluteName); recordRep.deleteRecord(fr); // Create a new FolderRecord and store this in the recordRepository // Can anybody explain me the use of this repository ??? // I think OpenMailbox and Repository is relatively redundant fr = new SimpleFolderRecord(user, absolutenewName); fr.setUidValidity( mmm.getUIDValidity() ); fr.setLookupRights( mmm.getUsersWithLookupRights() ); fr.setReadRights( mmm.getUsersWithReadRights() ); fr.setMarked( mmm.isMarked() ); fr.setNotSelectableByAnyone( mmm.isNotSelectableByAnyone() ); fr.setExists( mmm.getExists() ); fr.setRecent( mmm.getRecent() ); fr.setUnseenbyUser( mmm.getUnseenByUser() ); recordRep.store(fr); // Remove old entry from openMailboxes and create a new one this.openMailboxes.removeMailbox(oldAbsoluteName); mailbox = getAbsoluteMailbox( user, absolutenewName ); this.openMailboxes.addMailbox(absolutenewName,mailbox); return true; } else { return false; } } } } } return false; } catch (Exception e) { e.printStackTrace(); throw new AuthorizationException("You have insufficient permission to change the Mailbox Name"); } } /** * Returns the namespace which should be used for this user unless they * expicitly request another. * * @param username String an email address * @return a String of a namespace */ public String getDefaultNamespace( String username ) { return PRIVATE_NAMESPACE_PREFIX; } /** * Return UIDValidity for named mailbox. Implementations should track * existing and deleted folders. * * @param mailbox String name of the existing mailbox * @return an integer containing the current UID Validity value. */ // public int getUIDValidity(String mailbox); /** * Returns an iterator over an unmodifiable collection of Strings * representing mailboxes on this host and their attributes. The specified * user must have at least lookup rights for each mailbox returned. * If the subscribedOnly flag is set, only mailboxes to which the * specified user is currently subscribed should be returned. * Implementations that may export circular hierarchies SHOULD restrict the * levels of hierarchy returned. The depth suggested by rfc 2683 is 20 * hierarchy levels. * <p>The reference name must be non-empty. If the mailbox name is empty, * implementations must not throw either exception but must return a single * String (described below) if the reference name specifies a local mailbox * accessible to the user and a one-character String containing the * hierarchy delimiter of the referenced namespace, otherwise. * <p>Each String returned should be a space seperated triple of name * attributes, hierarchy delimiter and full mailbox name. The mailbox * name should include the namespace and be relative to the specified user. * <p> RFC comments: Implementations SHOULD return quickly. They SHOULD * NOT go to excess trouble to calculate\Marked or \Unmarked status. * <p>JAMES comment: By elimination, implementations should usually include * \Noinferiors or \Noselect, if appropriate. Also, if the reference name * and mailbox name resolve to a single local mailbox, implementations * should establish all attributes. * <p> Note that servers cannot unilaterally remove mailboxes from the * subscribed list. A request with the subscribedOnly flag set that * attempts to list a deleted mailbox must return that mailbox with the * \Noselect attribute. * * @param username String non-empty email address of requester * @param referenceName String non-empty name, including namespace, of a * mailbox or level of mailbox hierarchy, relative to user. * @param mailboxName String name of a mailbox possible including a * wildcard. * @param subscribedOnly only return mailboxes currently subscribed. * @return Collection of strings representing a set of mailboxes. * @throws AccessControlException if the user does not have at least * lookup rights to at least one mailbox in the set requested. * @throws MailboxException if the referenceName is not local or if * referenceName and mailbox name resolve to a single mailbox which does * not exist locally. */ public synchronized Collection listMailboxes( String username, String referenceName, String mailboxName, boolean subscribedOnly ) throws MailboxException, AccessControlException { getLogger().debug( "Listing for user: " + username + " ref " + referenceName + " mailbox " + mailboxName ); System.out.println( "Listing for user: '" + username + "' ref '" + referenceName + "' mailbox '" + mailboxName + "'"); List responseList = new ArrayList(); // For mailboxName == ""; return <"."> <namespace-of-reference> if ( mailboxName.equals( "" ) ) { String referenceNamespace = getNamespacePrefix( referenceName ); if ( referenceNamespace == null ) { getLogger().error( "Weird arguments for LIST? referenceName was: " + referenceName + " and mailbox names was " + mailboxName ); return null; } if ( referenceNamespace.length() == 0 ) { referenceNamespace = "\"\""; } String response = "(\\Noselect) \"" + HIERARCHY_SEPARATOR + "\" " + referenceNamespace; responseList.add( response ); return responseList; } try { getLogger().debug( "Refined mailboxName to: " + mailboxName ); String userTarget; if ( mailboxName.startsWith( NAMESPACE_TOKEN ) ) { userTarget = mailboxName; } else { if ( referenceName.length() == 0 || referenceName.endsWith( HIERARCHY_SEPARATOR ) ) { userTarget = referenceName + mailboxName; } else { userTarget = referenceName + HIERARCHY_SEPARATOR + mailboxName; } } String target = getAbsoluteMailboxName( username, userTarget ); getLogger().info( "Target is: " + target ); if ( target == null ) { return new HashSet(); } int firstPercent = target.indexOf( "%" ); int firstStar = target.indexOf( "*" ); getLogger().info( "First percent at index: " + firstPercent ); getLogger().info( "First star at index: " + firstStar ); System.out.println( "First percent at index: " + firstPercent ); System.out.println( "First star at index: " + firstStar ); // For now, only handle wildcards as last character of target. String targetMatch = target; boolean starWildcard = false; if ( firstStar > -1 ) { if ( firstStar != (target.length() - 1) ) { getLogger().debug( "Non-terminal * in LIST search." ); return null; } starWildcard = true; targetMatch = target.substring( 0, target.length() - 1 ); } boolean percentWildcard = false; if ( firstPercent > -1 ) { if ( firstPercent != (target.length() - 1) ) { getLogger().debug( "Non-terminal % in LIST search." ); return null; } percentWildcard = true; targetMatch = target.substring( 0, target.length() - 1 ); } Iterator all = recordRep.getAbsoluteNames(); Set matches = new HashSet(); while ( all.hasNext() ) { boolean match = false; String testMailboxName = (String) all.next(); getLogger().info( "Test is: " + testMailboxName ); if ( starWildcard ) { match = testMailboxName.startsWith( targetMatch ); } else if ( percentWildcard ) { match = (testMailboxName.startsWith( targetMatch ) && testMailboxName.lastIndexOf( HIERARCHY_SEPARATOR ) < targetMatch.length()); } else { // no wildcards so exact or nothing match = testMailboxName.equals( target ); getLogger().debug( "match/ no match at testMailboxName 1" ); } if ( match && subscribedOnly ) { ACLMailbox mailbox = getAbsoluteMailbox( username, testMailboxName ); if (! mailbox.isSubscribed( username ) ) { match = false; } releaseMailbox( username, mailbox ); } if ( match ) { getLogger().info( "Processing match for : " + testMailboxName ); FolderRecord record = recordRep.retrieve( testMailboxName ); ACLMailbox mailbox = null; StringBuffer buf = new StringBuffer(); buf.append( "(" ); if ( !record.isDeleted() && openMailboxes.contains( target ) ) { mailbox = openMailboxes.getMailbox( target ); } if ( record.isDeleted() ) { buf.append( "\\Noselect" ); } else if ( openMailboxes.contains( target ) ) { mailbox = openMailboxes.getMailbox( target ); if ( !mailbox.isSelectable( username ) ) { buf.append( "\\Noselect" ); } if ( mailbox.isMarked() ) { buf.append( "\\Marked" ); } else { buf.append( "\\Unmarked" ); } } else { if ( !record.isSelectable( username ) ) { buf.append( "\\Noselect" ); } if ( record.isMarked() ) { buf.append( "\\Marked" ); } else { buf.append( "\\Unmarked" ); } } buf.append( ") \"" ); buf.append( HIERARCHY_SEPARATOR ); buf.append( "\" \"" ); buf.append( getUserAwareMailboxName( username, testMailboxName ) ); buf.append( "\"" ); matches.add( buf.toString() ); } } return matches; } catch ( Exception e ) { getLogger().error( "Exception with list request for mailbox " + mailboxName ); e.printStackTrace(); return null; } } private String getNamespacePrefix( String mailbox ) { if ( mailbox.startsWith( USER_NAMESPACE_PREFIX ) ) { return USER_NAMESPACE_PREFIX; } else if ( mailbox.startsWith( SHARE_NAMESPACE_PREFIX ) ) { return SHARE_NAMESPACE_PREFIX; } else { return PRIVATE_NAMESPACE_PREFIX; } } /** * Subscribes a userName to a mailbox. The mailbox must exist locally and the * userName must have at least lookup rights to it. * * @param username String representation of an email address * @param mailbox String representation of a mailbox name. * @return true if subscribe completes successfully * @throws AccessControlException if the mailbox exists but the userName does * not have lookup rights. * @throws MailboxException if the mailbox does not exist locally. */ public boolean subscribe( 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.subscribe( userName ); releaseMailbox( userName, mailbox ); return true; } /** * Unsubscribes from a given mailbox. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -