本文整理汇总了Java中javax.mail.Folder.close方法的典型用法代码示例。如果您正苦于以下问题:Java Folder.close方法的具体用法?Java Folder.close怎么用?Java Folder.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.Folder
的用法示例。
在下文中一共展示了Folder.close方法的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: receiveByFolder
import javax.mail.Folder; //导入方法依赖的package包/类
public void receiveByFolder(Folder folder, JavamailConfig javamailConfig)
throws MessagingException, IOException {
logger.info("receive : {}", folder);
if ((Folder.HOLDS_MESSAGES & folder.getType()) != 0) {
this.receiveMessageByFolder(folder, javamailConfig);
}
if ((Folder.HOLDS_FOLDERS & folder.getType()) != 0) {
for (Folder childFolder : folder.list()) {
this.receiveByFolder(childFolder, javamailConfig);
}
}
if (folder.isOpen()) {
// 关闭资源
folder.close(false);
}
}
示例5: 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);
}
示例6: 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);
}
示例7: 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);
}
示例8: 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].setText("Message " + i);
messages[i].setHeader("Message-ID", "myuid-" + i);
}
folder.appendMessages(messages);
folder.close(true);
}
示例9: 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();
}
示例10: clear
import javax.mail.Folder; //导入方法依赖的package包/类
private static void clear(Folder folder) throws MessagingException {
if(folder.exists() && (folder.getType() & Folder.HOLDS_MESSAGES) == Folder.HOLDS_MESSAGES) {
int totMessages = folder.getMessageCount();
System.out.println(totMessages + " messages from folder: " + folder.getFullName());
folder.open(Folder.READ_WRITE);
Message[] messages = folder.getMessages();
for (int i = 0; i < messages.length; i++) {
System.out.println("Deleting message: " + (i+1) + " of " + totMessages);
messages[i].setFlag(Flags.Flag.DELETED, true);
}
folder.close(true);
}
Folder[] childs = folder.list();
for (int i = 0; i < childs.length; i++) {
clear(childs[i]);
}
}
示例11: 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();
}
示例12: compact
import javax.mail.Folder; //导入方法依赖的package包/类
public String compact() throws MessagingException
{
Folder folder = _folderData.getFolder();
folder.open(Folder.READ_WRITE);
// It would be much more efficient to simply trim out
// the list of "expunged" messages from the data model;
// instead, we're refreshing the list.
folder.expunge();
folder.close(true);
return refresh();
}
示例13: 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 8 new messages
Message[] messages = new Message[5];
for (int i = 0; i < 5; i++) {
messages[i] = new MimeMessage(sender.getSession());
messages[i].setText("Message " + i);
messages[i].setHeader("Message-ID", "" + i);
}
folder.appendMessages(messages);
folder.close(true);
}
示例14: _getEmail
import javax.mail.Folder; //导入方法依赖的package包/类
public MessageWrapper _getEmail( String hostName, MessageFilter[] messageFilters, Map<String, String> propertyMap )
{
Properties mailProps = new Properties();
mailProps.putAll( propertyMap );
List<Message> messageList = new ArrayList<Message>( 10 );
MessageWrapper messageWrapper = null;
try
{
Session emailSession = Session.getDefaultInstance( mailProps );
Store store = emailSession.getStore( propertyMap.get( PROTOCOL ) );
store.connect( hostName, propertyMap.get( USER_NAME ), propertyMap.get( PASSWORD ) );
Folder emailFolder = store.getFolder( propertyMap.get( FOLDER_NAME ) != null ? propertyMap.get( FOLDER_NAME ) : DEFAULT_FOLDER_NAME );
emailFolder.open( Folder.READ_WRITE );
Message[] messages = emailFolder.getMessages();
int messageCount = emailFolder.getMessageCount();
if ( messageCount > MAX_MESSAGES )
messageCount = MAX_MESSAGES;
if ( log.isInfoEnabled() )
log.info( "Processing " + messageCount + " messages" );
for ( int i = 0; i < messageCount; i++ )
{
if ( applyFilters( messages[i], messageFilters ) )
{
messageList.add( messages[i] );
}
}
if ( messageList.size() == 0 )
throw new ScriptException( "Failed to find any email messages that met the criteria" );
Collections.sort( messageList, new DateComparator() );
String messageContent = null;
String contentType = messageList.get( 0 ).getContentType();
if ( contentType.startsWith( "text/" ) )
messageContent = messageList.get( 0 ).getContent().toString();
else if ( messageList.get( 0 ).isMimeType( "multipart/*" ) )
messageContent = getTextFromMimeMultipart( (MimeMultipart) messageList.get( 0 ).getContent() );
else
messageContent = messageList.get( 0 ).getContent().getClass().getName();
messageWrapper = new MessageWrapper( messageList.size(), messageList.get( 0 ).getFrom()[0].toString(), messageList.get( 0 ).getSubject(), messageContent, contentType );
emailFolder.close( false );
store.close();
}
catch ( Exception e )
{
e.printStackTrace();
throw new ScriptException( "Failed to find email" );
}
return messageWrapper;
}
示例15: receive
import javax.mail.Folder; //导入方法依赖的package包/类
/**
* �����ʼ�
*/
public static void receive() throws Exception {
// �����ӷ������ĻỰ��Ϣ
Properties props = new Properties();
props.setProperty("mail.store.protocol", "pop3"); // ��
props.setProperty("mail.pop3.port", "110"); // �˿�
props.setProperty("mail.pop3.host", "pop3.sina.com"); // pop3������
// ����Sessionʵ������
Session session = Session.getInstance(props);
Store store = session.getStore("pop3");
store.connect("[email protected]", "mh899821671104");
// ����ռ���
Folder folder = store.getFolder("INBOX");
/* Folder.READ_ONLY��ֻ��Ȩ��
* Folder.READ_WRITE���ɶ���д���������ʼ���״̬��
*/
folder.open(Folder.READ_WRITE); //���ռ���
// ����POP3Э������֪�ʼ���״̬,����getUnreadMessageCount�õ������ռ�����ʼ�����
System.out.println("δ���ʼ���: " + folder.getUnreadMessageCount());
// ����POP3Э������֪�ʼ���״̬,��������õ��Ľ��ʼ�ն���Ϊ0
System.out.println("ɾ���ʼ���: " + folder.getDeletedMessageCount());
System.out.println("���ʼ�: " + folder.getNewMessageCount());
// ����ռ����е��ʼ�����
System.out.println("�ʼ�����: " + folder.getMessageCount());
// �õ��ռ����е������ʼ�,������
Message[] messages = folder.getMessages();
parseMessage(messages);
//�ͷ���Դ
folder.close(true);
store.close();
}