📄 filemailbox.java
字号:
this.absoluteName = this.absoluteName.substring(0,this.absoluteName.length()-this.name.length())+lastnameofmailbox; this.name=lastnameofmailbox; this.writeMailbox(); return true; }catch(Exception e) { e.printStackTrace(); return false; } } /** * THIS IS AN INTERIM SOLUTION ! * * @param usernmae The Username who calles this Command. * @param oldabsolutename The old name of the parent. * @param newabsolutename The new name for the parent. * @return true if everythink was sucessfully, else false. * @throws MailboxException if mailbox does not exist locally. * @throws AuthorizationException if the user has no rights for changing the name of the Mailbox. */ public boolean renameSubMailbox(String username, String oldabsolutename, String newname) { try { System.out.println("renameSubMailbox ABSOLUTE NAME "+this.absoluteName); StringTokenizer strt = new StringTokenizer(oldabsolutename,"."); StringBuffer strbuff = new StringBuffer(); for(int i=0;i<strt.countTokens();i++){ String token = strt.nextToken(); if(strbuff.length()>0) strbuff.append("."); strbuff.append(token); } strbuff.append("."); strbuff.append(newname); this.absoluteName = strbuff.toString()+this.absoluteName.substring(oldabsolutename.length()); System.out.println("renameSubMailbox TOKEN CONVERTED: "+this.absoluteName); this.writeMailbox(); return true; }catch(Exception e) { e.printStackTrace(); return false; } } /** * Returns true once this Mailbox has been checkpointed. * This implementation just writes its mailbox record to disc. Unless something is * broken all messages added, amended or removed from this mailbox will have been * handled by this object. * <br> This implementation always returns true. * * @return true */ public synchronized boolean checkpoint() { writeMailbox(); getLogger().info("FileMailbox: " + absoluteName + " checkpointed."); return true; } /** * Remove \Recent flag from all messages in mailbox. Should be called * whenever a user session finishes. */ public synchronized void unsetRecent() { Iterator it = recentMessages.iterator(); while(it.hasNext()) { Integer uidObj =(Integer)it.next(); int uid = uidObj.intValue(); Flags flags = readFlags(uid); if (flags != null) { flags.setRecent(false); writeFlags(uid, flags); } } recentMessages.clear(); } // Methods that don't involve the ACL ------------------ /** * Returns name of this mailbox relative to its parent in the mailbox * hierarchy. * Example: 'NewIdeas' * * @return String name of mailbox relative to its immeadiate parent in * the mailbox hierarchy. */ public String getName() { return name; } /** * Returns absolute, that is user-independent, hierarchical name of * mailbox (including namespace) * Example: '#mail.fred.flintstone.apache.James.NewIdeas' * * @return String name of mailbox in absolute form */ public String getAbsoluteName() { return absoluteName; } /** Returns namespace starting with namespace token. * Example: '#mail' * * @return String containing user-independent namespace of this mailbox. */ // public String getNamespace(); /** Returns true if the argument is the relative or absolute name of * this mailbox * * @param name possible name for this Mailbox * @return true if name matches either getName() or getAbsoluteName() */ public boolean matchesName(String testName) { return (name.equals(testName) || name.equals(absoluteName)); } /** * Returns the current unique id validity value of this mailbox. * * @return int current 32 bit unique id validity value of this mailbox */ public int getUIDValidity() { return uidValidity; } /** * Returns the 32 bit uid available for the next message. * * @return int the next UID that would be used. */ public int getNextUID() { return highestUID.get() + 1; } /** * Returns mailbox size in octets. Should only include actual messages * and not any implementation-specific data, such as message attributes. * * @return int mailbox size in octets */ public synchronized int getMailboxSize() { return mailboxSize; } /** * Indicates if child folders may be created. It does not indicate which * users can create child folders. * * @return boolean TRUE if inferiors aree allowed */ public boolean getInferiorsAllowed() { return inferiorsAllowed; } /** * Indicates that messages have been added since this mailbox was last * selected by any user. * * @return boolean TRUE if new messages since any user last selected * mailbox */ public synchronized boolean isMarked() { return marked; } /** * Returns all flags supported by this mailbox. * e.g. \Answered \Deleted * * @return String a space seperated list of message flags which are * supported by this mailbox. */ public String getSupportedFlags() { return SYSTEM_FLAGS; } /** * Indicates no of messages with \Recent flag set * * @return int no of messages with \Recent flag set */ public synchronized int getRecent() { return recentMessages.size(); } /** * Indicates the oldest unseen message for the specified user. * * @return int Message Sequence Number of first message without \Seen * flag set for this User. 0 means no unseen messages in this mailbox. */ public synchronized int getOldestUnseen(String user) { int response = 0; if (oldestUnseenMessage.containsKey(user)) { Integer uidObj = ((Integer)oldestUnseenMessage.get(user)); if (! (uidObj.intValue() == 0)) { response = sequence.indexOf(uidObj) + 1; } } else { if (sequence.size() > 0) { response = 1; oldestUnseenMessage.put(user, (Integer)sequence.get(0)); } else { oldestUnseenMessage.put(user, (new Integer(0))); } } return response; } /** * Indicates number of messages in folder * * @return int number of messages */ public synchronized int getExists() { return sequence.size(); } /** * Indicates the number of unseen messages for the specified user. * * @return int number of messages without \Seen flag set for this User. */ public int getUnseen(String user) { if (oldestUnseenMessage.containsKey(user)) { int response = 0; //indicates no unseen messages Integer uidObj = ((Integer)oldestUnseenMessage.get(user)); int oldUID = uidObj.intValue(); if (oldUID != 0) { ListIterator lit = sequence.listIterator(sequence.indexOf(uidObj)); while (lit.hasNext() ) { int uid = ((Integer)lit.next()).intValue(); Flags flags = readFlags(uid); if (!flags.isSeen(user)) { response ++; } } } return response; } else { // user has never selected mailbox return sequence.size(); } } /** Mailbox Events are used to inform registered listeners of events in the Mailbox. * E.g. if mail is delivered to an Inbox or if another user appends/ deletes a message. */ public synchronized void addMailboxEventListener(MailboxEventListener mel) { listeners.add(mel); } public synchronized void removeMailboxEventListener(MailboxEventListener mel) { listeners.remove(mel); } /** * Mark this mailbox as not selectable by anyone. * Example folders at the roots of hierarchies, e. #mail for each user. * * @param state true if folder is not selectable by anyone */ public void setNotSelectableByAnyone(boolean state) { notSelectableByAnyone = state; } public boolean isNotSelectableByAnyone() { return notSelectableByAnyone; } // Methods for the embedded ACL ------------------------ /** * Store access rights for a given identity. * The setter is the user setting the rights, the identifier is the user * whose rights are affected. * The setter and identifier arguments must be non-null and non-empty. * The modification argument must be non-null and follow the syntax of the * third argument to a SETACL command. * If the modification argument is an empty string, that identifier is * removed from the ACL, if currently present. * * @param setter String representing user attempting to set rights, must * be non-null and non-empty * @param identity String representing user whose rights are being set, * must be non-null and non-empty * @param modification String representing the change in rights, following * the syntax specified in rfc 2086. Note a blank string means delete all * rights for given identity. * @return true if requested modification succeeded. A return value of * false means an error other than an AccessControlException or * AuthorizationException. * @throws AccessControlException if setter does not have lookup rights for * this mailbox (ie they should not know this mailbox exists). * @throws AuthorizationException if specified setter does not have the * administer right (ie the right to write ACL rights), or if the result * of this method would leave no identities with admin rights. */ public boolean setRights(String setter, String identifier, String modification) throws AccessControlException, AuthorizationException { boolean[] settersRights = (boolean[]) acl.get(setter); if (settersRights == null || (settersRights[LOOKUP] == false)) { throw new AccessControlException(DENY_ACCESS); } else if (settersRights[ADMIN] == false) { throw new AuthorizationException(DENY_AUTH + setter); } boolean[] existingRights = (boolean[]) acl.get(identifier); char[] mods = modification.toCharArray(); if (mods.length == 0) { // means delete all mods = DELETE_MODS; } if(existingRights == null) { if ( mods[0] == REMOVE_RIGHTS ) { return false; } else { existingRights = new boolean[NUMBER_OF_RIGHTS]; System.arraycopy(NO_RIGHTS, 0, existingRights, 0, NUMBER_OF_RIGHTS); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -