本文整理汇总了Java中com.sun.mail.imap.IMAPFolder.expunge方法的典型用法代码示例。如果您正苦于以下问题:Java IMAPFolder.expunge方法的具体用法?Java IMAPFolder.expunge怎么用?Java IMAPFolder.expunge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.mail.imap.IMAPFolder
的用法示例。
在下文中一共展示了IMAPFolder.expunge方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUIDExpunge
import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
@Test
public void testUIDExpunge() throws MessagingException {
greenMail.setUser("[email protected]", "pwd");
// Create some test emails
int numberOfEmails = 10;
long[] uids = new long[numberOfEmails];
for (int i = 0; i < numberOfEmails; i++) {
GreenMailUtil.sendTextEmail("[email protected]", "[email protected]", "Test UID expunge #" + i,
"Test message", greenMail.getSmtp().getServerSetup());
}
final IMAPStore store = greenMail.getImap().createStore();
store.connect("[email protected]", "pwd");
try {
IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
Message[] messages = folder.getMessages();
assertEquals(numberOfEmails, messages.length);
// Mark even as deleted ...
Message[] msgsForDeletion = new Message[uids.length / 2];
for (int i = 0; i < messages.length; i++) {
assertFalse(messages[i].getFlags().contains(Flags.Flag.DELETED));
uids[i] = folder.getUID(messages[i]);
if (i % 2 == 0) { // Deleted
messages[i].setFlag(Flags.Flag.DELETED, true);
msgsForDeletion[i / 2] = messages[i];
}
}
// ... and expunge (with UID)
folder.expunge(msgsForDeletion);
// Check
for (int i = 0; i < uids.length; i++) {
final Message message = folder.getMessageByUID(uids[i]);
if (i % 2 == 0) { // Deleted
assertNull(message);
} else {
assertTrue("" + i, !message.isExpunged());
assertTrue("" + i, !message.getFlags().contains(Flags.Flag.DELETED));
}
}
} finally {
store.close();
}
}
示例2: copySourceMessages
import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
/**
* Once the folder structure has been created it copies messages recursively from the root
* folder.
*
* @param sourceFolder
* @throws MessagingException
*/
private void copySourceMessages(IMAPFolder sourceFolder) throws MessagingException {
if (sourceFolder != null) {
final String sourceFolderName = sourceFolder.getFullName();
final String targetFolderName
= MNIMAPSync.translateFolderName(sourceSeparator, targetSeparator,
sourceFolderName);
if ((sourceFolder.getType() & Folder.HOLDS_MESSAGES) == Folder.HOLDS_MESSAGES) {
//Manage Servers with public/read only folders.
try {
sourceFolder.open(Folder.READ_WRITE);
} catch (ReadOnlyFolderException ex) {
sourceFolder.open(Folder.READ_ONLY);
}
if (sourceFolder.getMode() != Folder.READ_ONLY) {
sourceFolder.expunge();
}
///////////////////////
final int messageCount = sourceFolder.getMessageCount();
sourceFolder.close(false);
int pos = 1;
while (pos + MNIMAPSync.BATCH_SIZE <= messageCount) {
//Copy messages
service.execute(new MessageCopier(this, sourceFolderName, targetFolderName, pos,
pos + MNIMAPSync.BATCH_SIZE, targetIndex.getFolderMessages(
targetFolderName)));
pos = pos + MNIMAPSync.BATCH_SIZE;
}
service.execute(new MessageCopier(this, sourceFolderName, targetFolderName, pos,
messageCount,
targetIndex.getFolderMessages(targetFolderName)));
}
//Folder recursion. Get all children
if ((sourceFolder.getType() & Folder.HOLDS_FOLDERS) == Folder.HOLDS_FOLDERS) {
for (Folder child : sourceFolder.list()) {
copySourceMessages((IMAPFolder) child);
}
}
}
}
示例3: deleteTargetMessages
import com.sun.mail.imap.IMAPFolder; //导入方法依赖的package包/类
private void deleteTargetMessages(IMAPFolder targetFolder) throws MessagingException {
if (targetFolder != null) {
final String targetFolderName = targetFolder.getFullName();
final String sourceFolderName = MNIMAPSync.translateFolderName(targetSeparator,
sourceSeparator, targetFolderName);
if ((targetFolder.getType() & Folder.HOLDS_MESSAGES) == Folder.HOLDS_MESSAGES) {
targetFolder.open(Folder.READ_WRITE);
if (targetFolder.getMode() != Folder.READ_ONLY) {
targetFolder.expunge();
}
final int messageCount = targetFolder.getMessageCount();
targetFolder.close(false);
int pos = 1;
while (pos + MNIMAPSync.BATCH_SIZE <= messageCount) {
service.execute(
new MessageDeleter(this, sourceFolderName, targetFolderName, pos,
pos + MNIMAPSync.BATCH_SIZE, false, sourceIndex.
getFolderMessages(sourceFolderName)));
pos = pos + MNIMAPSync.BATCH_SIZE;
}
service.execute(new MessageDeleter(this, sourceFolderName, targetFolderName,
pos, messageCount, true, sourceIndex.getFolderMessages(sourceFolderName)));
}
//Folder recursion. Get all children
if ((targetFolder.getType() & Folder.HOLDS_FOLDERS) == Folder.HOLDS_FOLDERS) {
for (Folder child : targetFolder.list()) {
deleteTargetMessages((IMAPFolder) child);
}
}
}
}