org.YoUmail.maildir
Class MaildirFolder

java.lang.Object
  extended byjavax.mail.Folder
      extended byorg.YoUmail.maildir.MaildirFolder

public final class MaildirFolder
extends javax.mail.Folder

The folder class implementing a Maildir-format mailbox.

Author:
Chris Burdess,modified by topmint@163.com

Nested Class Summary
(package private) static class MaildirFolder.MaildirFilter
          Filename filter that rejects dotfiles.
(package private)  class MaildirFolder.MaildirListFilter
          Filename filter for listing subfolders.
(package private) static class MaildirFolder.MaildirTuple
          Structure holding the details for a maildir subdirectory.
 
Nested classes inherited from class javax.mail.Folder
 
Field Summary
(package private)  MaildirFolder.MaildirTuple curdir
          The maildir cur directory.
(package private) static long deliveryCount
           
(package private) static java.io.FilenameFilter filter
          Singleton instance of filter.
(package private)  boolean inbox
           
(package private) static java.lang.String INBOX
           
 MaildirMessage[] m
           
(package private)  java.io.File maildir
          The maildir base directory.
(package private)  MaildirFolder.MaildirTuple newdir
          The maildir new directory.
(package private) static javax.mail.Flags permanentFlags
           
(package private)  java.io.File tmpdir
          The maildir tmp directory.
(package private)  int type
           
 
Fields inherited from class javax.mail.Folder
HOLDS_FOLDERS, HOLDS_MESSAGES, mode, READ_ONLY, READ_WRITE, store
 
Constructor Summary
protected MaildirFolder(javax.mail.Store store, java.lang.String filename)
          Constructor.
protected MaildirFolder(javax.mail.Store store, java.lang.String filename, boolean root, boolean inbox)
          构造函数
 
Method Summary
 void appendMessages(javax.mail.Message[] m)
          Appends messages to this folder.
 void close(boolean expunge)
          Closes this folder.
 boolean create(int type)
          Creates this folder in the store.
(package private) static java.lang.String createUniq()
          Create a unique filename.
 boolean delete(boolean recurse)
          Deletes this folder.
(package private)  boolean delete(java.io.File file)
          Depth-first file/directory delete.
 void delete(java.lang.String[] msglist)
          彻底删除
 boolean exists()
          Indicates whether this folder exists.
 javax.mail.Message[] expunge()
          Expunges this folder.
 MaildirMessage[] getAllMessages(int order, int desc)
          返回所有按指定顺序排序过的邮件
 javax.mail.Folder getFolder(java.lang.String filename)
          Returns the subfolder of this folder with the specified name.
 java.lang.String getFullName()
          Returns the full name of this folder.
 javax.mail.Message getMessage(int msgnum)
          Returns the specified message number from this folder.
 int getMessageCount()
          Returns the number of messages in this folder.
 javax.mail.Message[] getMessages()
          Returns the messages in this folder.
 MaildirMessage[] getMessages(int start, int end, int order, int desc)
          读取信件,从位置start到end,按指定顺序排序
 java.lang.String getName()
          Returns the name of this folder.
 int getNewMessageCount()
          Returns the number of new messages in this folder.
 javax.mail.Folder getParent()
          Returns the parent folder.
 javax.mail.Flags getPermanentFlags()
          Returns the permanent flags for this folder.
 char getSeparator()
          Returns the separator character.
 long getSize()
          统计文件夹所有邮件大小
 int getType()
          Returns the type of this folder.
 javax.mail.URLName getURLName()
          Return a URLName representing this folder.
 boolean hasNewMessages()
          Indicates whether this folder contains new messages.
 boolean isOpen()
          Indicates whether this folder is open.
 javax.mail.Folder[] list()
          Returns the subfolders of this folder.
 javax.mail.Folder[] list(java.lang.String pattern)
          Returns the subfolders of this folder matching the specified pattern.
 void Moveto(javax.mail.Folder folder, java.lang.String[] msglist)
          移动消息到目标邮件夹
 void open(int mode)
          Opens this folder.
private  MaildirMessage[] QuickSort(MaildirMessage[] m, int order, int desc)
          排序
 boolean renameTo(javax.mail.Folder folder)
          Renames this folder.
 int searchMessage(MaildirMessage[] m, java.lang.String msgname)
          搜索消息
 void setSeen(MaildirMessage message, boolean seen)
          Move the specified message between new and cur, depending on whether it has been seen or not.
(package private)  void statDir(MaildirFolder.MaildirTuple dir)
          Check the specified directory for messages, repopulating its messages member if necessary, and updating its timestamp.
 
Methods inherited from class javax.mail.Folder
addConnectionListener, addFolderListener, addMessageChangedListener, addMessageCountListener, copyMessages, fetch, finalize, getMessages, getMessages, getMode, getStore, getUnreadMessageCount, isSubscribed, listSubscribed, listSubscribed, notifyConnectionListeners, notifyFolderListeners, notifyFolderRenamedListeners, notifyMessageAddedListeners, notifyMessageChangedListeners, notifyMessageRemovedListeners, removeConnectionListener, removeFolderListener, removeMessageChangedListener, removeMessageCountListener, search, search, setFlags, setFlags, setFlags, setSubscribed, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

filter

static final java.io.FilenameFilter filter
Singleton instance of filter.


INBOX

static final java.lang.String INBOX
See Also:
Constant Field Values

maildir

java.io.File maildir
The maildir base directory.


tmpdir

java.io.File tmpdir
The maildir tmp directory.


newdir

MaildirFolder.MaildirTuple newdir
The maildir new directory.


curdir

MaildirFolder.MaildirTuple curdir
The maildir cur directory.


m

public MaildirMessage[] m

type

int type

inbox

boolean inbox

permanentFlags

static javax.mail.Flags permanentFlags

deliveryCount

static long deliveryCount
Constructor Detail

MaildirFolder

protected MaildirFolder(javax.mail.Store store,
                        java.lang.String filename,
                        boolean root,
                        boolean inbox)
构造函数

Parameters:
store -
filename -
root -
inbox -

MaildirFolder

protected MaildirFolder(javax.mail.Store store,
                        java.lang.String filename)
Constructor.

Method Detail

getName

public java.lang.String getName()
Returns the name of this folder.


getFullName

public java.lang.String getFullName()
Returns the full name of this folder.


getURLName

public javax.mail.URLName getURLName()
                              throws javax.mail.MessagingException
Return a URLName representing this folder.

Throws:
javax.mail.MessagingException

getType

public int getType()
Returns the type of this folder.


exists

public boolean exists()
Indicates whether this folder exists.


hasNewMessages

public boolean hasNewMessages()
Indicates whether this folder contains new messages.


open

public void open(int mode)
          throws javax.mail.MessagingException
Opens this folder. If the folder is opened for writing, a lock must be acquired on the mbox. If this fails a MessagingException is thrown.

Throws:
javax.mail.MessagingException - if a messaging error occurred

close

public void close(boolean expunge)
           throws javax.mail.MessagingException
Closes this folder.

Parameters:
expunge - if the folder is to be expunged before it is closed
Throws:
javax.mail.MessagingException - if a messaging error occurred

expunge

public javax.mail.Message[] expunge()
                             throws javax.mail.MessagingException
Expunges this folder. This deletes all the messages marked as deleted.

Throws:
javax.mail.MessagingException - if a messaging error occurred

isOpen

public boolean isOpen()
Indicates whether this folder is open.


getPermanentFlags

public javax.mail.Flags getPermanentFlags()
Returns the permanent flags for this folder.


getMessageCount

public int getMessageCount()
Returns the number of messages in this folder.


getNewMessageCount

public int getNewMessageCount()
Returns the number of new messages in this folder.


getMessage

public javax.mail.Message getMessage(int msgnum)
                              throws javax.mail.MessagingException
Returns the specified message number from this folder.

Throws:
javax.mail.MessagingException - if a messaging error occurred

getMessages

public javax.mail.Message[] getMessages()
                                 throws javax.mail.MessagingException
Returns the messages in this folder.

Throws:
javax.mail.MessagingException - if a messaging error occurred

statDir

void statDir(MaildirFolder.MaildirTuple dir)
Check the specified directory for messages, repopulating its messages member if necessary, and updating its timestamp.


setSeen

public void setSeen(MaildirMessage message,
                    boolean seen)
             throws javax.mail.MessagingException
Move the specified message between new and cur, depending on whether it has been seen or not.

Throws:
javax.mail.MessagingException

appendMessages

public void appendMessages(javax.mail.Message[] m)
                    throws javax.mail.MessagingException
Appends messages to this folder. Only MimeMessages within the array will be appended, as we don't know how to retrieve internet content for other kinds.

Parameters:
m - an array of messages to be appended
Throws:
javax.mail.MessagingException

createUniq

static java.lang.String createUniq()
                            throws java.io.IOException
Create a unique filename.

Throws:
java.io.IOException

getParent

public javax.mail.Folder getParent()
                            throws javax.mail.MessagingException
Returns the parent folder.

Throws:
javax.mail.MessagingException

list

public javax.mail.Folder[] list()
                         throws javax.mail.MessagingException
Returns the subfolders of this folder.

Throws:
javax.mail.MessagingException

list

public javax.mail.Folder[] list(java.lang.String pattern)
                         throws javax.mail.MessagingException
Returns the subfolders of this folder matching the specified pattern.

Throws:
javax.mail.MessagingException

getSeparator

public char getSeparator()
Returns the separator character.


create

public boolean create(int type)
               throws javax.mail.MessagingException
Creates this folder in the store.

Throws:
javax.mail.MessagingException

delete

public boolean delete(boolean recurse)
               throws javax.mail.MessagingException
Deletes this folder.

Throws:
javax.mail.MessagingException

delete

boolean delete(java.io.File file)
         throws java.lang.SecurityException
Depth-first file/directory delete.

Throws:
java.lang.SecurityException

renameTo

public boolean renameTo(javax.mail.Folder folder)
                 throws javax.mail.MessagingException
Renames this folder.

Throws:
javax.mail.MessagingException

getFolder

public javax.mail.Folder getFolder(java.lang.String filename)
                            throws javax.mail.MessagingException
Returns the subfolder of this folder with the specified name.

Throws:
javax.mail.MessagingException

Moveto

public void Moveto(javax.mail.Folder folder,
                   java.lang.String[] msglist)
            throws javax.mail.MessagingException
移动消息到目标邮件夹

Parameters:
folder - 目标邮件夹
msglist - 消息列表
Throws:
javax.mail.MessagingException

delete

public void delete(java.lang.String[] msglist)
            throws javax.mail.MessagingException
彻底删除

Parameters:
msglist -
Throws:
javax.mail.MessagingException

searchMessage

public int searchMessage(MaildirMessage[] m,
                         java.lang.String msgname)
搜索消息

Parameters:
msgname - 消息名称
Returns:
消息所在位置

getSize

public long getSize()
             throws javax.mail.MessagingException
统计文件夹所有邮件大小

Returns:
合计大小
Throws:
javax.mail.MessagingException

getMessages

public MaildirMessage[] getMessages(int start,
                                    int end,
                                    int order,
                                    int desc)
                             throws javax.mail.MessagingException
读取信件,从位置start到end,按指定顺序排序

Parameters:
start - 开始位置
end - 结束位置
order - 排序方法,如按标题排序
desc - 是否倒排
Returns:
指定的信件集
Throws:
javax.mail.MessagingException

QuickSort

private MaildirMessage[] QuickSort(MaildirMessage[] m,
                                   int order,
                                   int desc)
排序

Parameters:
m -
order - 排序方法,如按标题排序
desc - 是否倒排
Returns:
排好序的邮件集

getAllMessages

public MaildirMessage[] getAllMessages(int order,
                                       int desc)
                                throws javax.mail.MessagingException
返回所有按指定顺序排序过的邮件

Parameters:
order - 排序方法,如按标题排序
desc - 是否倒排
Returns:
邮件集
Throws:
javax.mail.MessagingException