本文整理汇总了Java中javax.mail.Folder.getFolder方法的典型用法代码示例。如果您正苦于以下问题:Java Folder.getFolder方法的具体用法?Java Folder.getFolder怎么用?Java Folder.getFolder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.Folder
的用法示例。
在下文中一共展示了Folder.getFolder方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTestMessages
import javax.mail.Folder; //导入方法依赖的package包/类
public void createTestMessages() {
try {
GreenMailUser user = greenMail.setUser(TEST_RECIP, "password");
final String subject = GreenMailUtil.random();
final String body = GreenMailUtil.random();
user.deliver(createMimeMessage("[email protected]", subject, body, null));
user.deliver(createMimeMessage("[email protected]", "Great stuff cheap!", "body", null));
user.deliver(createMimeMessage("[email protected]", "Happening this month", "stuff", null));
user.deliver(createMimeMessage("[email protected]", "Get certified today!", "Cheap!", null));
user.deliver(createMimeMessage("[email protected]", "It's been a long time!", "Let's talk", null));
user.deliver(createMimeMessage("[email protected]", "The Sound of Drums", "boom boom boom",
Date.from(LocalDate.now().minusYears(2).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())));
Session imapSession = greenMail.getImap().createSession();
Store store = imapSession.getStore("imap");
store.connect(TEST_RECIP, "password");
Folder defaultFolder = store.getDefaultFolder();
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
Folder ads = defaultFolder.getFolder("Ads");
ads.create(Folder.HOLDS_MESSAGES);
Folder spam = defaultFolder.getFolder("Spam");
spam.create(Folder.HOLDS_MESSAGES);
} catch (MessagingException ex) {
Logger.getLogger(TestMailUtil.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例2: checkInbox
import javax.mail.Folder; //导入方法依赖的package包/类
public void checkInbox(int mode) throws MessagingException, IOException {
if (mode == 0) {
return;
}
boolean show = (mode & MailClient.SHOW_MESSAGES) > 0;
boolean clear = (mode & MailClient.CLEAR_MESSAGES) > 0;
String action = (show ? "Show" : "") + (show && clear ? " and " : "") + (clear ? "Clear" : "");
System.out.println(action + " INBOX for " + from);
Store store = session.getStore();
store.connect();
Folder root = store.getDefaultFolder();
Folder inbox = root.getFolder("inbox");
inbox.open(Folder.READ_WRITE);
Message[] msgs = inbox.getMessages();
if (msgs.length == 0 && show) {
System.out.println("No messages in inbox");
}
for (Message msg2 : msgs) {
MimeMessage msg = (MimeMessage) msg2;
if (show) {
System.out.println(" From: " + msg.getFrom()[0]);
System.out.println(" Subject: " + msg.getSubject());
System.out.println(" Content: " + msg.getContent());
}
if (clear) {
msg.setFlag(Flags.Flag.DELETED, true);
}
}
inbox.close(true);
store.close();
System.out.println();
}
示例3: checkInboxSave
import javax.mail.Folder; //导入方法依赖的package包/类
public void checkInboxSave(int mode) throws MessagingException, IOException {
Store store = session.getStore();
store.connect();
Folder root = store.getDefaultFolder();
Folder inbox = root.getFolder("inbox");
inbox.open(Folder.READ_WRITE);
Message[] msgs = inbox.getMessages();
for (Message msg2 : msgs) {
POP3Message msg = (POP3Message) msg2;
Object object = msg.getContent();
if (object instanceof Multipart) {
Multipart multipart = (Multipart) object;
for (int i = 0, n = multipart.getCount(); i < n; i++) {
MailClient.handlePart(multipart.getBodyPart(i));
}
}
System.out.println(" From: " + msg.getFrom()[0]);
System.out.println(" Subject: " + msg.getSubject());
System.out.println(" Content: " + object);
}
inbox.close(true);
store.close();
}
示例4: openFolder
import javax.mail.Folder; //导入方法依赖的package包/类
private Folder openFolder( cfSession _Session, Store popStore ) throws cfmRunTimeException {
try{
Folder folder = popStore.getDefaultFolder();
Folder popFolder = folder.getFolder("INBOX");
popFolder.open( Folder.READ_WRITE );
return popFolder;
}catch(Exception E){
throw newRunTimeException( E.getMessage() );
}
}
示例5: checkMessages
import javax.mail.Folder; //导入方法依赖的package包/类
protected void checkMessages(Store store, Session session) throws MessagingException {
if (!store.isConnected()) {
store.connect();
}
// open the default folder
Folder folder = store.getDefaultFolder();
if (!folder.exists()) {
throw new MessagingException("No default (root) folder available");
}
// open the inbox
folder = folder.getFolder(INBOX);
if (!folder.exists()) {
throw new MessagingException("No INBOX folder available");
}
// get the message count; stop if nothing to do
folder.open(Folder.READ_WRITE);
int totalMessages = folder.getMessageCount();
if (totalMessages == 0) {
folder.close(false);
return;
}
// get all messages
Message[] messages = folder.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
FetchProfile profile = new FetchProfile();
profile.add(FetchProfile.Item.ENVELOPE);
profile.add(FetchProfile.Item.FLAGS);
profile.add("X-Mailer");
folder.fetch(messages, profile);
// process each message
for (Message message: messages) {
// process each un-read message
if (!message.isSet(Flags.Flag.SEEN)) {
long messageSize = message.getSize();
if (message instanceof MimeMessage && messageSize >= maxSize) {
Debug.logWarning("Message from: " + message.getFrom()[0] + "not received, too big, size:" + messageSize + " cannot be more than " + maxSize + " bytes", module);
// set the message as read so it doesn't continue to try to process; but don't delete it
message.setFlag(Flags.Flag.SEEN, true);
} else {
this.processMessage(message, session);
if (Debug.verboseOn()) Debug.logVerbose("Message from " + UtilMisc.toListArray(message.getFrom()) + " with subject [" + message.getSubject() + "] has been processed." , module);
message.setFlag(Flags.Flag.SEEN, true);
if (Debug.verboseOn()) Debug.logVerbose("Message [" + message.getSubject() + "] is marked seen", module);
// delete the message after processing
if (deleteMail) {
if (Debug.verboseOn()) Debug.logVerbose("Message [" + message.getSubject() + "] is being deleted", module);
message.setFlag(Flags.Flag.DELETED, true);
}
}
}
}
// expunge and close the folder
folder.close(true);
}