到目前为止,我们已经在前面的章节主要介绍收件箱文件夹的工作。这是大多数邮件位于其中的默认文件夹。有些系统可能会调用它的收件箱和其他一些可能被其他一些名字来称呼它。但是,你总是可以从JavaMail API为使用该名称的收件箱访问它。
JavaMail API为代表文件夹的文件夹抽象类的实例:
publicabstractclassFolderextendsObject
这个类声明请求命名文件夹从服务器,从文件夹中删除邮件,搜索文件夹中特定消息,列出文件夹中的邮件,等等方法。
打开文件夹
我们不能直接创建一个文件夹中 Folder 类唯一的构造函数是受保护的。我们可以得到一个文件夹从:
Session
Store
另外的Folder
上述所有的类都有一个类似的getFolder()方法类似签名:
publicabstractFoldergetFolder(Stringname)throwsMessagingException
一些在其中获取Folder 对象帮助的方法有:
方法
描述
boolean exists()
Checks if the folder really exists. Use this method before getting the Folder object.
abstract void open(int mode)
When you get a Folder, its closed. Use this method to open it. modecan be Folder.READ_ONLY or Folder.READ_WRITE.
abstract boolean isOpen()
This method returns true if the folder is open, false if it’s closed
abstract void close(boolean expunge)
Closes the folder. If the expunge argument is true, any deleted messages in the folder are deleted from the actual file on the server. Otherwise, they’re simply marked asdeleted, but the messages can still be undeleted.
基本文件夹信息
以下是一些它返回有关一个文件夹的基本信息,文件夹类中的方法:
方法
描述
abstract String getName()
Returns the name of the folder, such as "TutorialsPoint Mail"
abstract