本文整理汇总了Java中javax.mail.Folder.open方法的典型用法代码示例。如果您正苦于以下问题:Java Folder.open方法的具体用法?Java Folder.open怎么用?Java Folder.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.Folder
的用法示例。
在下文中一共展示了Folder.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteMails
import javax.mail.Folder; //导入方法依赖的package包/类
/**
* Connect to the mail server and delete all mails.
*/
public void deleteMails() throws MessagingException {
Folder folder = getStore().getFolder(MAIL_INBOX);
folder.open(Folder.READ_WRITE);
// Get folder's list of messages.
Message[] messages = folder.getMessages();
// Retrieve message headers for each message in folder.
FetchProfile profile = new FetchProfile();
profile.add(FetchProfile.Item.ENVELOPE);
folder.fetch(messages, profile);
for (Message message : messages) {
message.setFlag(Flags.Flag.DELETED, true);
}
folder.close(true);
}
示例2: changeStatus
import javax.mail.Folder; //导入方法依赖的package包/类
public void changeStatus( String folderName, long mailIDs[], Flags.Flag newFlag, boolean value ){
try{
Folder folderToUse = mailStore.getFolder(folderName);
folderToUse.open( Folder.READ_WRITE );
Flags f = new Flags();
f.add( newFlag );
Message mlist[];
if ( folderToUse instanceof UIDFolder )
mlist = ((UIDFolder)folderToUse).getMessagesByUID( mailIDs );
else
mlist = folderToUse.getMessages( returnToInts(mailIDs) );
for ( int x=0; x < mlist.length; x++ )
mlist[x].setFlags( f, value );
folderToUse.close( true );
setData( "succeeded", cfBooleanData.TRUE );
} catch (Exception E ){
setData( "errortext", new cfStringData( E.getMessage() ) );
setData( "succeeded", cfBooleanData.FALSE );
}
}
示例3: prepareMailbox
import javax.mail.Folder; //导入方法依赖的package包/类
private void prepareMailbox() throws Exception {
// connect to mailbox
Mailbox.clearAll();
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore("pop3");
store.connect("localhost", 25, "jones", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts 5 new messages
Message[] messages = new Message[5];
for (int i = 0; i < 5; i++) {
messages[i] = new MimeMessage(sender.getSession());
messages[i].setHeader("Message-ID", "" + i);
messages[i].setText("Message " + i);
}
folder.appendMessages(messages);
folder.close(true);
}
示例4: reconnectStoreIfClosed
import javax.mail.Folder; //导入方法依赖的package包/类
/**
* Reconnects if connection is closed.
* <b>Note</b>Internal method
* @return true if store re-connection is performed and this means that close should be closed after the work is done
* @throws MessagingException
*/
public boolean reconnectStoreIfClosed() throws MessagingException {
boolean storeReconnected = false;
// the folder is empty when the message is not loaded from IMAP server, but from a file
Folder imapFolder = message.getFolder();
if (imapFolder == null) {
imapFolder = this.partOfImapFolder;
} else {
partOfImapFolder = imapFolder; // keep reference
}
if (imapFolder != null) {
Store store = imapFolder.getStore();
if (store != null) {
if (!store.isConnected()) {
log.debug("Reconnecting store... ");
store.connect();
storeReconnected = true;
}
// Open folder in read-only mode
if (!imapFolder.isOpen()) {
log.debug("Reopening folder " + imapFolder.getFullName()
+ " in order to get contents of mail message");
imapFolder.open(Folder.READ_ONLY);
}
}
}
return storeReconnected;
}
示例5: getFolder
import javax.mail.Folder; //导入方法依赖的package包/类
private Folder getFolder(String folderName, int mode) {
Folder source = null;
try {
if (folders.containsKey(folderName)) {
source = folders.get(folderName);
} else {
source = store.getFolder(folderName);
if (source == null || !source.exists()) {
throw new IllegalArgumentException("Invalid folder: " + folderName);
}
folders.put(folderName, source);
}
if (!source.isOpen()) {
source.open(mode);
}
} catch (MessagingException ex) {
Logger.getLogger(AccountProcessor.class.getName()).log(Level.SEVERE, null, ex);
}
return source;
}
示例6: 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);
}
}
示例7: prepareMailbox
import javax.mail.Folder; //导入方法依赖的package包/类
private void prepareMailbox() throws Exception {
// connect to mailbox
Mailbox.clearAll();
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore("imap");
store.connect("localhost", 25, "claus", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts two messages with the SEEN flag
Message[] msg = new Message[2];
msg[0] = new MimeMessage(sender.getSession());
msg[0].setText("Message 1");
msg[0].setHeader("Message-ID", "0");
msg[0].setFlag(Flags.Flag.SEEN, true);
msg[1] = new MimeMessage(sender.getSession());
msg[1].setText("Message 2");
msg[0].setHeader("Message-ID", "1");
msg[1].setFlag(Flags.Flag.SEEN, true);
folder.appendMessages(msg);
folder.close(true);
}
示例8: prepareMailbox
import javax.mail.Folder; //导入方法依赖的package包/类
private void prepareMailbox(String user, String type) throws Exception {
// connect to mailbox
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore(type);
store.connect("localhost", 25, user, "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
InputStream is = getClass().getResourceAsStream("/SignedMailTestCaseHurz.elm");
Message hurzMsg = new MimeMessage(sender.getSession(), is);
Message[] messages = new Message[] {hurzMsg};
// insert one signed message
folder.appendMessages(messages);
folder.close(true);
}
示例9: deleteAllEmails
import javax.mail.Folder; //导入方法依赖的package包/类
/**
* Delete all emails in the inbox.
*
* @param protocol protocol used to connect to the server
* @throws MessagingException if we're unable to connect to the store
*/
public static void deleteAllEmails(String protocol, GreenMailUser user) throws MessagingException {
Folder inbox = null;
Store store = getConnection(user, protocol);
try {
inbox = store.getFolder(EMAIL_INBOX);
inbox.open(Folder.READ_WRITE);
Message[] messages = inbox.getMessages();
for (Message message : messages) {
message.setFlag(Flags.Flag.DELETED, true);
log.info("Deleted email Subject : " + message.getSubject());
}
} finally {
if (inbox != null) {
inbox.close(true);
}
if (store != null) {
store.close();
}
}
}
示例10: prepareMailbox
import javax.mail.Folder; //导入方法依赖的package包/类
private void prepareMailbox() throws Exception {
// connect to mailbox
Mailbox.clearAll();
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore("imap");
store.connect("localhost", 25, "claus", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts two new messages
Message[] msg = new Message[2];
msg[0] = new MimeMessage(sender.getSession());
msg[0].setText("Message 1");
msg[0].setHeader("Message-ID", "0");
msg[0].setFlag(Flags.Flag.SEEN, false);
msg[1] = new MimeMessage(sender.getSession());
msg[1].setText("Message 2");
msg[0].setHeader("Message-ID", "1");
msg[1].setFlag(Flags.Flag.SEEN, true);
folder.appendMessages(msg);
folder.close(true);
}
示例11: prepareMailbox
import javax.mail.Folder; //导入方法依赖的package包/类
private void prepareMailbox() throws Exception {
// connect to mailbox
Mailbox.clearAll();
JavaMailSender sender = new DefaultJavaMailSender();
Store store = sender.getSession().getStore("pop3");
store.connect("localhost", 25, "bill", "secret");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.expunge();
// inserts 1 new message
Message[] messages = new Message[1];
messages[0] = new MimeMessage(sender.getSession());
messages[0].setSubject("TestSubject");
messages[0].setHeader("Message-ID", "0");
messages[0].setText("TestText");
folder.appendMessages(messages);
folder.close(true);
}
示例12: 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();
}
示例13: deleteMails
import javax.mail.Folder; //导入方法依赖的package包/类
/**
* delete all message in ibox that match given criteria
* @param messageNumbers
* @param uIds
* @throws MessagingException
* @throws IOException
*/
public void deleteMails(String as[], String as1[]) throws MessagingException, IOException {
Folder folder;
Message amessage[];
folder = _fldelse.getFolder("INBOX");
folder.open(2);
Map<String, Message> map = getMessages(null,folder, as1, as, startrow, maxrows,false);
Iterator<String> iterator = map.keySet().iterator();
amessage = new Message[map.size()];
int i = 0;
while(iterator.hasNext()) {
amessage[i++] = map.get(iterator.next());
}
try {
folder.setFlags(amessage, new Flags(javax.mail.Flags.Flag.DELETED), true);
}
finally {
folder.close(true);
}
}
示例14: main
import javax.mail.Folder; //导入方法依赖的package包/类
public static void main(String[] args) throws MessagingException {
String url = "https://outlook.office365.com/ews/exchange.asmx";
Properties properties = new Properties();
properties.setProperty("org.sourceforge.net.javamail4ews.util.Util.EnableServiceTrace", "true");
Session session = Session.getInstance(properties);
System.out.println("retrieving the store");
//Get the EWS store implementation
Store store = session.getStore("ewsstore");
System.out.println("done");
//Connect to the Exchange server - No port required.
//Also connect() might be used if the session is initalized with the known mail.* properties
System.out.println(String.format("connecting to %s", url));
store.connect(url,
"[email protected]",
"p4ssw0rd");
System.out.println(String.format("connected to %s", url));
System.out.println(String.format("get default folder", url));
Folder folder = store.getDefaultFolder();
System.out.println(String.format("open default folder as read-only"));
folder.open(Folder.READ_ONLY);
System.out.println(String.format("done"));
Message[] messages = folder.getMessages();
System.out.println(String.format("there is %d messages", messages.length));
System.out.println(messages[0].getFrom());
}
示例15: 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();
}