com.sun.mail.imap.IMAPFolder Java Examples
The following examples show how to use
com.sun.mail.imap.IMAPFolder.
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: ImapMessageTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Returns a full message body * * @param folder Folder containing the message * @param uid Message UID * @return Returns size of the message * @throws MessagingException */ private static BODY getMessageBody(IMAPFolder folder, final Long uid) throws MessagingException { return (BODY) folder.doCommand(new IMAPFolder.ProtocolCommand() { public Object doCommand(IMAPProtocol p) throws ProtocolException { Response[] r = p.command("UID FETCH " + uid + " (FLAGS BODY.PEEK[])", null); logResponse(r); Response response = r[r.length - 1]; // Grab response if (!response.isOK()) { throw new ProtocolException("Unable to retrieve message size"); } FetchResponse fetchResponse = (FetchResponse) r[0]; BODY body = (BODY) fetchResponse.getItem(BODY.class); return body; } }); }
Example #2
Source File: ImapProtocolTest.java From greenmail with Apache License 2.0 | 6 votes |
@Test public void testListAndStatusWithNonExistingFolder() throws MessagingException { store.connect("foo@localhost", "pwd"); try { IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); assertFalse(folder.getFolder("non existent folder").exists()); for (final String cmd : new String[]{ "STATUS \"non existent folder\" (MESSAGES UIDNEXT UIDVALIDITY UNSEEN)", "SELECT \"non existent folder\"" }) { Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() { @Override public Object doCommand(IMAPProtocol protocol) { return protocol.command(cmd, null); } }); IMAPResponse response = (IMAPResponse) ret[0]; assertTrue(response.isNO()); } } finally { store.close(); } }
Example #3
Source File: ImapProtocolTest.java From greenmail with Apache License 2.0 | 6 votes |
@Test public void testSearchNotFlags() throws MessagingException { store.connect("foo@localhost", "pwd"); try { IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX"); folder.open(Folder.READ_WRITE); folder.setFlags(new int[]{2, 3}, new Flags(Flags.Flag.ANSWERED), true); Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() { @Override public Object doCommand(IMAPProtocol protocol) { return protocol.command("SEARCH NOT (ANSWERED) NOT (DELETED) NOT (SEEN) NOT (FLAGGED) ALL", null); } }); IMAPResponse response = (IMAPResponse) ret[0]; assertFalse(response.isBAD()); assertEquals("1 4 5 6 7 8 9 10" /* 2 and 3 set to answered */, response.getRest()); } finally { store.close(); } }
Example #4
Source File: ImapProtocolTest.java From greenmail with Apache License 2.0 | 6 votes |
@Test public void testGetMessageByUnknownUidInEmptyINBOX() throws MessagingException, FolderException { greenMail.getManagers() .getImapHostManager() .getInbox(user) .deleteAllMessages(); store.connect("foo@localhost", "pwd"); try { IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); Message message = folder.getMessageByUID(666); assertNull(message); } finally { store.close(); } }
Example #5
Source File: IMAPTestCase.java From javamail-mock2 with Apache License 2.0 | 6 votes |
@Override public void run() { while (!Thread.interrupted()) { try { // System.out.println("enter idle"); ((IMAPFolder) folder).idle(); idleCount++; // System.out.println("leave idle"); } catch (final Exception e) { exception = e; } } // System.out.println("leave run()"); }
Example #6
Source File: Main.java From javamail-mock2 with Apache License 2.0 | 6 votes |
@Override public void run() { while (!Thread.interrupted()) { try { // System.out.println("enter idle"); ((IMAPFolder) folder).idle(); idleCount++; // System.out.println("leave idle"); Thread.sleep(500); } catch (final Exception e) { exception = e; } } // System.out.println("leave run()"); }
Example #7
Source File: MailListener.java From Ardulink-1 with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws MessagingException { initConfiguration(); initInbox(); System.out.println("Messages in inbox: " + inbox.getMessageCount()); // Add messageCountListener to listen for new messages inbox.addMessageCountListener(new ArdulinkMailMessageCountAdapter()); // TODO pezzo da rivedere. Perch� casto a IMAP se l'ho messo in configurazione? Perch� // casto ad una classe proprietaria della SUN? // NON esiste codice pi� standard? // Se ho un listener non posso semplicemente ciclare questo thread con una sleep? // int freq = 1000; while(true) { IMAPFolder f = (IMAPFolder)inbox; f.idle(); System.out.println("IDLE done"); } }
Example #8
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 #9
Source File: MailNotificationService.java From camunda-bpm-mail with Apache License 2.0 | 6 votes |
public void start(String folderName) throws Exception { executorService = Executors.newSingleThreadExecutor(); Folder folder = mailService.ensureOpenFolder(folderName); folder.addMessageCountListener(new MessageCountAdapter() { @Override public void messagesAdded(MessageCountEvent event) { List<Message> messages = Arrays.asList(event.getMessages()); handlers.forEach(handler -> handler.accept(messages)); } }); if (supportsIdle(folder)) { notificationWorker = new IdleNotificationWorker(mailService, (IMAPFolder) folder); } else { notificationWorker = new PollNotificationWorker(mailService, folder, configuration.getNotificationLookupTime()); } LOGGER.debug("start notification service: {}", notificationWorker); executorService.submit(notificationWorker); }
Example #10
Source File: IdleNotificationWorker.java From camunda-bpm-mail with Apache License 2.0 | 6 votes |
@Override public void stop() { runnning = false; // perform a NOOP to interrupt IDLE try { folder.doCommand(new IMAPFolder.ProtocolCommand() { public Object doCommand(IMAPProtocol p) throws ProtocolException { p.simpleCommand("NOOP", null); return null; } }); } catch (MessagingException e) { // ignore } }
Example #11
Source File: MessageId.java From mnIMAPSync with Apache License 2.0 | 6 votes |
/** * Adds required headers to fetch profile */ public static FetchProfile addHeaders(FetchProfile fetchProfile) { fetchProfile.add(FetchProfile.Item.ENVELOPE); //Some servers respond to get a header request with a partial response of the header //when hMailServer is fetched for To or From, it returns only the first entry, //so when compared with other server versions, e-mails appear to be different. fetchProfile.add(IMAPFolder.FetchProfileItem.HEADERS); //If using the header consructor add this for performance. // for (String header : new String[]{ // MessageId.HEADER_MESSAGE_ID, // MessageId.HEADER_SUBJECT, // MessageId.HEADER_FROM, // MessageId.HEADER_TO}) { // fetchProfile.add(header.toUpperCase()); // } return fetchProfile; }
Example #12
Source File: ImapMessageTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Returns BODY object containing desired message fragment * * @param folder Folder containing the message * @param uid Message UID * @param from starting byte * @param count bytes to read * @return BODY containing desired message fragment * @throws MessagingException */ private static BODY getMessageBodyPart(IMAPFolder folder, final Long uid, final Integer from, final Integer count) throws MessagingException { return (BODY) folder.doCommand(new IMAPFolder.ProtocolCommand() { public Object doCommand(IMAPProtocol p) throws ProtocolException { Response[] r = p.command("UID FETCH " + uid + " (FLAGS BODY.PEEK[]<" + from + "." + count + ">)", null); logResponse(r); Response response = r[r.length - 1]; // Grab response if (!response.isOK()) { throw new ProtocolException("Unable to retrieve message part <" + from + "." + count + ">"); } FetchResponse fetchResponse = (FetchResponse) r[0]; BODY body = (BODY) fetchResponse.getItem(com.sun.mail.imap.protocol.BODY.class); return body; } }); }
Example #13
Source File: Core.java From FairEmail with GNU General Public License v3.0 | 6 votes |
private static void onFlag(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException, JSONException { // Star/unstar message DB db = DB.getInstance(context); if (!ifolder.getPermanentFlags().contains(Flags.Flag.FLAGGED)) { db.message().setMessageFlagged(message.id, false); db.message().setMessageUiFlagged(message.id, false, null); return; } boolean flagged = jargs.getBoolean(0); if (message.flagged.equals(flagged)) return; Message imessage = ifolder.getMessageByUID(message.uid); if (imessage == null) throw new MessageRemovedException(); imessage.setFlag(Flags.Flag.FLAGGED, flagged); db.message().setMessageFlagged(message.id, flagged); }
Example #14
Source File: StoreCopier.java From mnIMAPSync with Apache License 2.0 | 6 votes |
/** * Once the folder structure has been created it copies messages recursively from the root * folder. */ private void copySourceMessages(IMAPFolder sourceFolder) throws MessagingException { if (sourceFolder != null) { final String sourceFolderName = sourceFolder.getFullName(); final String targetFolderName = sourceFolderNameToTarget(sourceFolderName, sourceIndex, targetIndex); 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); } } } }
Example #15
Source File: Core.java From FairEmail with GNU General Public License v3.0 | 6 votes |
private static void onAnswered(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException, JSONException { // Mark message (un)answered DB db = DB.getInstance(context); if (!ifolder.getPermanentFlags().contains(Flags.Flag.ANSWERED)) { db.message().setMessageAnswered(message.id, false); db.message().setMessageUiAnswered(message.id, false); return; } boolean answered = jargs.getBoolean(0); if (message.answered.equals(answered)) return; // This will be fixed when moving the message if (message.uid == null) return; Message imessage = ifolder.getMessageByUID(message.uid); if (imessage == null) throw new MessageRemovedException(); imessage.setFlag(Flags.Flag.ANSWERED, answered); db.message().setMessageAnswered(message.id, answered); }
Example #16
Source File: Core.java From FairEmail with GNU General Public License v3.0 | 6 votes |
private static void onKeyword(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException, JSONException { // Set/reset user flag DB db = DB.getInstance(context); // https://tools.ietf.org/html/rfc3501#section-2.3.2 String keyword = jargs.getString(0); boolean set = jargs.getBoolean(1); if (TextUtils.isEmpty(keyword)) throw new IllegalArgumentException("keyword/empty"); if (!ifolder.getPermanentFlags().contains(Flags.Flag.USER)) { db.message().setMessageKeywords(message.id, DB.Converters.fromStringArray(null)); return; } if (message.uid == null) throw new IllegalArgumentException("keyword/uid"); Message imessage = ifolder.getMessageByUID(message.uid); if (imessage == null) throw new MessageRemovedException(); Flags flags = new Flags(keyword); imessage.setFlags(flags, set); }
Example #17
Source File: Core.java From FairEmail with GNU General Public License v3.0 | 6 votes |
private static void onSeen(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException, JSONException { // Mark message (un)seen DB db = DB.getInstance(context); if (!ifolder.getPermanentFlags().contains(Flags.Flag.SEEN)) { db.message().setMessageSeen(message.id, false); db.message().setMessageUiSeen(message.id, false); return; } boolean seen = jargs.getBoolean(0); if (message.seen.equals(seen)) return; Message imessage = ifolder.getMessageByUID(message.uid); if (imessage == null) throw new MessageRemovedException(); imessage.setFlag(Flags.Flag.SEEN, seen); db.message().setMessageSeen(message.id, seen); }
Example #18
Source File: ImapMessageTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private static RFC822DATA getRFC822Message(final IMAPFolder folder, final long uid) throws MessagingException { return (RFC822DATA) folder.doCommand(new IMAPFolder.ProtocolCommand() { public Object doCommand(IMAPProtocol p) throws ProtocolException { Response[] r = p.command("UID FETCH " + uid + " (RFC822)", null); logResponse(r); Response response = r[r.length - 1]; if (!response.isOK()) { throw new ProtocolException("Unable to retrieve message in RFC822 format"); } FetchResponse fetchResponse = (FetchResponse) r[0]; return fetchResponse.getItem(RFC822DATA.class); } }); }
Example #19
Source File: Core.java From FairEmail with GNU General Public License v3.0 | 6 votes |
private static void onBody(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException, IOException { // Download message body DB db = DB.getInstance(context); if (message.content) return; // Get message Message imessage = ifolder.getMessageByUID(message.uid); if (imessage == null) throw new MessageRemovedException(); MessageHelper helper = new MessageHelper((MimeMessage) imessage, context); MessageHelper.MessageParts parts = helper.getMessageParts(); String body = parts.getHtml(context); File file = message.getFile(context); Helper.writeText(file, body); db.message().setMessageContent(message.id, true, HtmlHelper.getLanguage(context, body), parts.isPlainOnly(), HtmlHelper.getPreview(body), parts.getWarnings(message.warning)); }
Example #20
Source File: ImapProtocolTest.java From greenmail with Apache License 2.0 | 5 votes |
@Test public void testUidSearchAll() throws MessagingException, IOException { greenMail.setUser("foo2@localhost", "pwd"); store.connect("foo2@localhost", "pwd"); try { IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); final MimeMessage email = GreenMailUtil.createTextEmail("foo2@localhost", "foo@localhost", "some subject", "some content", greenMail.getSmtp().getServerSetup()); final IMAPFolder.ProtocolCommand uid_search_all = new IMAPFolder.ProtocolCommand() { @Override public Object doCommand(IMAPProtocol protocol) { return protocol.command("UID SEARCH ALL", null); } }; // Search empty Response[] ret = (Response[]) folder.doCommand(uid_search_all); IMAPResponse response = (IMAPResponse) ret[0]; assertFalse(response.isBAD()); assertEquals("* SEARCH", response.toString()); } finally { store.close(); } }
Example #21
Source File: ImapProtocolTest.java From greenmail with Apache License 2.0 | 5 votes |
@Test public void testRenameFolder() throws MessagingException { store.connect("foo@localhost", "pwd"); try { IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX"); folder.open(Folder.READ_WRITE); Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() { @Override public Object doCommand(IMAPProtocol protocol) { return protocol.command("CREATE foo", null); } }); IMAPResponse response = (IMAPResponse) ret[0]; assertFalse(response.isBAD()); ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() { @Override public Object doCommand(IMAPProtocol protocol) { return protocol.command("RENAME foo bar", null); } }); Response response2 = ret[0]; assertTrue(response2.isOK()); final Folder bar = store.getFolder("bar"); bar.open(Folder.READ_ONLY); assertTrue(bar.exists()); } finally { store.close(); } }
Example #22
Source File: ImapProtocolTest.java From greenmail with Apache License 2.0 | 5 votes |
@Test public void testUidSearchTextWithCharset() throws MessagingException, IOException { greenMail.setUser("foo2@localhost", "pwd"); store.connect("foo2@localhost", "pwd"); try { IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); final MimeMessage email = GreenMailUtil.createTextEmail("foo2@localhost", "foo@localhost", "some subject", "some content", greenMail.getSmtp().getServerSetup()); String[][] s = { {"US-ASCII", "ABC", "1"}, {"ISO-8859-15", "\u00c4\u00e4\u20AC", "2"}, {"UTF-8", "\u00c4\u00e4\u03A0", "3"} }; for (String[] charsetAndQuery : s) { final String charset = charsetAndQuery[0]; final String search = charsetAndQuery[1]; email.setSubject("subject " + search, charset); GreenMailUtil.sendMimeMessage(email); // messages[2] contains content with search text, match must be case insensitive final byte[] searchBytes = search.getBytes(charset); final Argument arg = new Argument(); arg.writeBytes(searchBytes); // Try with and without quotes searchAndValidateWithCharset(folder, charsetAndQuery[2], charset, arg); searchAndValidateWithCharset(folder, charsetAndQuery[2], '"' + charset + '"', arg); } } finally { store.close(); } }
Example #23
Source File: ImapProtocolTest.java From greenmail with Apache License 2.0 | 5 votes |
private void searchAndValidateWithCharset(IMAPFolder folder, String expected, String charset, Argument arg) throws MessagingException { Response[] ret = (Response[]) folder.doCommand(new IMAPFolder.ProtocolCommand() { @Override public Object doCommand(IMAPProtocol protocol) { return protocol.command("UID SEARCH CHARSET " + charset + " TEXT", arg); } }); IMAPResponse response = (IMAPResponse) ret[0]; assertFalse(response.isBAD()); String number = response.getRest(); assertEquals("Failed for charset " + charset, expected, number); }
Example #24
Source File: MessageCopierTest.java From mnIMAPSync with Apache License 2.0 | 5 votes |
@BeforeEach void setUp() throws Exception { imapFolder = Mockito.mock(IMAPFolder.class); doReturn('.').when(imapFolder).getSeparator(); imapStore = Mockito.mock(IMAPStore.class); doReturn(imapFolder).when(imapStore).getFolder(anyString()); doReturn(imapFolder).when(imapStore).getDefaultFolder(); sourceIndex = Mockito.spy(new Index()); targetIndex = Mockito.spy(new Index()); storeCopier = Mockito.spy(new StoreCopier(imapStore, sourceIndex, imapStore, targetIndex, 1)); }
Example #25
Source File: SenderRecipientTest.java From greenmail with Apache License 2.0 | 5 votes |
@Test public void testSendAndReceiveWithQuotedAddress() throws MessagingException, IOException { // See https://en.wikipedia.org/wiki/Email_address#Local-part String[] toList = {"\"John..Doe\"@localhost", "abc.\"defghi\".xyz@localhost", "\"abcdefghixyz\"@localhost", "\"Foo Bar\"admin@localhost" }; for(String to: toList) { greenMail.setUser(to, "pwd"); InternetAddress[] toAddress = InternetAddress.parse(to); String from = to; // Same from and to address for testing correct escaping of both final String subject = "testSendAndReceiveWithQuotedAddress"; final String content = "some body"; GreenMailUtil.sendTextEmailTest(to, from, subject, content); assertTrue(greenMail.waitForIncomingEmail(5000, 1)); final IMAPStore store = greenMail.getImap().createStore(); store.connect(to, "pwd"); try { IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); Message[] msgs = folder.getMessages(); assertTrue(null != msgs && msgs.length == 1); final Message msg = msgs[0]; assertEquals(to, ((InternetAddress)msg.getRecipients(Message.RecipientType.TO)[0]).getAddress()); assertEquals(from, ((InternetAddress)msg.getFrom()[0]).getAddress()); assertEquals(subject, msg.getSubject()); assertEquals(content, msg.getContent().toString()); assertArrayEquals(toAddress, msg.getRecipients(Message.RecipientType.TO)); } finally { store.close(); } } }
Example #26
Source File: StoreDeleterTest.java From mnIMAPSync with Apache License 2.0 | 5 votes |
@BeforeEach void setUp() throws Exception { imapFolder = Mockito.mock(IMAPFolder.class); doReturn("MissingFolder").when(imapFolder).getFullName(); doReturn(Folder.HOLDS_MESSAGES | Folder.HOLDS_FOLDERS).when(imapFolder).getType(); doReturn(new Folder[0]).when(imapFolder).list(); imapStore = Mockito.mock(IMAPStore.class); doReturn(imapFolder).when(imapStore).getFolder(anyString()); doReturn(imapFolder).when(imapStore).getDefaultFolder(); sourceIndex = Mockito.spy(new Index()); sourceIndex.setFolderSeparator("."); targetIndex = Mockito.spy(new Index()); targetIndex.setFolderSeparator("_"); }
Example #27
Source File: StoreCopierTest.java From mnIMAPSync with Apache License 2.0 | 5 votes |
@BeforeEach void setUp() throws Exception { imapFolder = Mockito.mock(IMAPFolder.class); doReturn('.').doReturn('_').when(imapFolder).getSeparator(); doReturn("INBOX").when(imapFolder).getFullName(); doReturn(Folder.HOLDS_MESSAGES | Folder.HOLDS_FOLDERS).when(imapFolder).getType(); doReturn(new Folder[0]).when(imapFolder).list(); imapStore = Mockito.mock(IMAPStore.class); doReturn(imapFolder).when(imapStore).getFolder(anyString()); doReturn(imapFolder).when(imapStore).getDefaultFolder(); sourceIndex = Mockito.spy(new Index()); sourceIndex.setFolderSeparator("."); targetIndex = Mockito.spy(new Index()); targetIndex.setFolderSeparator("_"); }
Example #28
Source File: StoreCrawlerText.java From mnIMAPSync with Apache License 2.0 | 5 votes |
@BeforeEach void setUp() throws Exception { defaultFolder = mockFolder("INBOX"); doReturn(new IMAPFolder[]{ mockFolder("Folder 1"), mockFolder("Folder 2") }).when(defaultFolder).list(); imapStore = Mockito.mock(IMAPStore.class); doReturn(defaultFolder).when(imapStore).getDefaultFolder(); doAnswer(invocation -> mockFolder(invocation.getArgument(0))) .when(imapStore).getFolder(anyString()); }
Example #29
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 #30
Source File: MessageDeleterTest.java From mnIMAPSync with Apache License 2.0 | 5 votes |
@BeforeEach void setUp() throws Exception { imapFolder = Mockito.mock(IMAPFolder.class); imapStore = Mockito.mock(IMAPStore.class); doReturn(imapFolder).when(imapStore).getFolder(anyString()); doReturn(imapFolder).when(imapStore).getDefaultFolder(); sourceIndex = Mockito.spy(new Index()); sourceIndex.setFolderSeparator("."); targetIndex = Mockito.spy(new Index()); targetIndex.setFolderSeparator("_"); storeDeleter = Mockito.spy(new StoreDeleter(sourceIndex, targetIndex, imapStore, 1)); }