Java Code Examples for javax.mail.Folder#isOpen()
The following examples show how to use
javax.mail.Folder#isOpen() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SyncUtils.java From ImapNote2 with GNU General Public License v3.0 | 6 votes |
public static void GetNotes(Account account, Folder notesFolder, Context ctx, NotesDb storedNotes) throws MessagingException, IOException{ Long UIDM; Message notesMessage; File directory = new File (ctx.getFilesDir() + "/" + account.name); if (notesFolder.isOpen()) { if ((notesFolder.getMode() & Folder.READ_ONLY) != 0) notesFolder.open(Folder.READ_ONLY); } else { notesFolder.open(Folder.READ_ONLY); } UIDValidity = GetUIDValidity(account, ctx); SetUIDValidity(account, UIDValidity, ctx); Message[] notesMessages = notesFolder.getMessages(); //Log.d(TAG,"number of messages in folder="+(notesMessages.length)); for(int index=notesMessages.length-1; index>=0; index--) { notesMessage = notesMessages[index]; // write every message in files/{accountname} directory // filename is the original message uid UIDM=((IMAPFolder)notesFolder).getUID(notesMessage); String suid = UIDM.toString(); File outfile = new File (directory, suid); GetOneNote(outfile, notesMessage, storedNotes, account.name, suid, true); } }
Example 2
Source File: JavamailService.java From lemon with Apache License 2.0 | 6 votes |
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); } }
Example 3
Source File: MimePackage.java From ats-framework with Apache License 2.0 | 5 votes |
/** * 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; }
Example 4
Source File: MailService.java From camunda-bpm-mail with Apache License 2.0 | 5 votes |
public Folder ensureOpenFolder(Folder folder) throws MessagingException { ensureConnectedStore(folder.getStore()); if (!folder.isOpen()) { openFolder(folder); } return folder; }
Example 5
Source File: cfMailMessageData.java From openbd-core with GNU General Public License v3.0 | 5 votes |
public void getMessage( cfImapConnection imapConnection, String rootFolder, long messageID, String _attachURI, String _attachDIR ) throws cfmRunTimeException { try{ Folder folderToList; if ( rootFolder == null || rootFolder.length() == 0 ) folderToList = imapConnection.mailStore.getDefaultFolder(); else folderToList = imapConnection.mailStore.getFolder(rootFolder); if ( (folderToList.getType() & Folder.HOLDS_MESSAGES) != 0){ if ( !folderToList.isOpen() ) folderToList.open( Folder.READ_ONLY ); boolean bResult = false; if ( folderToList instanceof UIDFolder ) bResult = extractMessage( ((UIDFolder)folderToList).getMessageByUID( messageID ), messageID, _attachURI, _attachDIR ); else bResult = extractMessage( folderToList.getMessage( (int)messageID ), messageID, _attachURI, _attachDIR ); if ( !bResult ) imapConnection.setStatus( false, "Message does not exist" ); else imapConnection.setStatus( true, "" ); folderToList.close(false); } }catch(Exception E){ imapConnection.setStatus( false, E.getMessage() ); } }
Example 6
Source File: SyncUtils.java From ImapNote2 with GNU General Public License v3.0 | 5 votes |
public static void DeleteNote(Folder notesFolder, int numMessage) throws MessagingException, IOException { notesFolder = store.getFolder(sfolder); if (notesFolder.isOpen()) { if ((notesFolder.getMode() & Folder.READ_WRITE) != 0) notesFolder.open(Folder.READ_WRITE); } else { notesFolder.open(Folder.READ_WRITE); } //Log.d(TAG,"UID to remove:"+numMessage); Message[] msgs = {((IMAPFolder)notesFolder).getMessageByUID(numMessage)}; notesFolder.setFlags(msgs, new Flags(Flags.Flag.DELETED), true); ((IMAPFolder)notesFolder).expunge(msgs); }
Example 7
Source File: IMAPUtils.java From elasticsearch-imap with Apache License 2.0 | 5 votes |
public static void close(final Folder folder) { try { if (folder != null && folder.isOpen()) { folder.close(false); } } catch (final Exception e) { // ignore } }
Example 8
Source File: cfMailFolderMessagesData.java From openbd-core with GNU General Public License v3.0 | 4 votes |
public cfQueryResultData listFolderMessages( cfImapConnection imapConnection, String rootFolder, int startRow, int totalMessages, boolean reverseOrder ) { cfQueryResultData query = new cfQueryResultData( new String[]{"subject","id","rxddate","sentdate","from","to","cc","bcc","size","lines","answered","deleted","draft","flagged","recent","seen"}, "CFIMAP" ); try{ Folder folderToList; if ( rootFolder == null || rootFolder.length() == 0 ) folderToList = imapConnection.mailStore.getDefaultFolder(); else folderToList = imapConnection.mailStore.getFolder(rootFolder); if ( (folderToList.getType() & Folder.HOLDS_MESSAGES) != 0){ if ( !folderToList.isOpen() ) folderToList.open( Folder.READ_ONLY ); Message[] messageArray; if ( startRow != -1 ){ int folderCount = folderToList.getMessageCount(); int start, end; if ( !reverseOrder ){ start = startRow; if ( folderCount < (startRow+totalMessages-1) ){ start = startRow; end = folderCount; }else{ end = startRow + totalMessages - 1; } }else{ end = folderCount - startRow + 1; if ( folderCount < (startRow+totalMessages-1) ){ start = 1; }else{ start = folderCount - startRow - totalMessages + 2; } } messageArray = folderToList.getMessages( start, end ); imapConnection.setTotalMessages( folderCount ); }else{ messageArray = folderToList.getMessages(); imapConnection.setTotalMessages( messageArray.length ); } // To improve performance, pre-fetch all of the message items // used by the CFIMAP list action. This will retrieve all of the // items for all of the messages with one single FETCH command. FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.ENVELOPE); fp.add(FetchProfile.Item.FLAGS); fp.add(FetchProfile.Item.CONTENT_INFO); folderToList.fetch(messageArray, fp); List<Map<String, cfData>> vectorMessages = new ArrayList<Map<String, cfData>>(messageArray.length); if ( reverseOrder ){ int msgIndex = messageArray.length-1; for (int i = 0; i < messageArray.length; i++) vectorMessages.add( extractMessage( messageArray[msgIndex--] ) ); }else{ for (int i = 0; i < messageArray.length; i++) vectorMessages.add( extractMessage( messageArray[i] ) ); } folderToList.close(false); query.populateQuery( vectorMessages ); } }catch(Exception E){ cfEngine.log( E.getMessage() ); imapConnection.setStatus( false, E.getMessage() ); } return query; }
Example 9
Source File: MailService.java From camunda-bpm-mail with Apache License 2.0 | 3 votes |
private void openFolder(Folder folder) throws MessagingException { LOGGER.debug("open folder '{}'", folder.getName()); folder.open(Folder.READ_WRITE); if (!folder.isOpen()) { throw new IllegalStateException("folder is not open"); } }
Example 10
Source File: IMAPUtils.java From elasticsearch-imap with Apache License 2.0 | 3 votes |
public static void open(final Folder folder) throws MessagingException { if (folder != null && folder.exists() && !folder.isOpen() && (folder.getType() & Folder.HOLDS_MESSAGES) != 0) { folder.open(Folder.READ_ONLY); } }