List of usage examples for javax.mail Flags Flags
public Flags()
From source file:org.apache.james.imap.processor.base.MailboxEventAnalyserTest.java
@Test public void testShouldNotSetUidWhenNoSystemFlagChange() throws Exception { MyMailboxSession mSession = new MyMailboxSession(11); MyImapSession imapsession = new MyImapSession(mSession); SelectedMailboxImpl analyser = new SelectedMailboxImpl(mockManager, imapsession, mailboxPath); final FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate(mSession, Arrays.asList(90L), Arrays.asList(new UpdatedFlags(90, -1, new Flags(), new Flags())), mailboxPath); analyser.event(update);/*from w w w.j a v a 2 s. co m*/ assertNotNull(analyser.flagUpdateUids()); assertFalse(analyser.flagUpdateUids().iterator().hasNext()); }
From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java
@Test public void getMessageListNOTOperatorShouldWork() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotSeenNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); ComposedMessageId messageNotSeenFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false, new Flags(Flags.Flag.FLAGGED)); ComposedMessageId messageSeenNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false, new Flags(Flags.Flag.SEEN)); ComposedMessageId messageSeenFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false, FlagsBuilder.builder().add(Flags.Flag.SEEN, Flags.Flag.FLAGGED).build()); await();//from w w w. j av a2s.co m given().header("Authorization", accessToken.serialize()).body( "[[\"getMessageList\", {\"filter\":{\"operator\":\"NOT\",\"conditions\":[{\"isFlagged\":\"true\"},{\"isUnread\":\"true\"}]}}, \"#0\"]]") .when().post("/jmap").then().statusCode(200).body(NAME, equalTo("messageList")) .body(ARGUMENTS + ".messageIds", allOf(containsInAnyOrder(messageSeenNotFlagged.getMessageId().serialize()), not(containsInAnyOrder(messageNotSeenFlagged.getMessageId().serialize(), messageSeenFlagged.getMessageId().serialize(), messageNotSeenNotFlagged.getMessageId().serialize())))); }
From source file:org.apache.james.jmap.methods.integration.SetMessagesMethodTest.java
@Test public void setMessagesShouldReturnUpdatedIdAndNoErrorWhenIsFlaggedPassed() throws MailboxException { // Given//from w w w. j a va2s .c om jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags()); await(); String presumedMessageId = username + "|mailbox|1"; given().header("Authorization", accessToken.serialize()) .body(String.format( "[[\"setMessages\", {\"update\": {\"%s\" : { \"isFlagged\" : true } } }, \"#0\"]]", presumedMessageId)) // When .when().post("/jmap") // Then .then().log().ifValidationFails().spec(getSetMessagesUpdateOKResponseAssertions(presumedMessageId)); }
From source file:org.apache.james.imap.processor.base.MailboxEventAnalyserTest.java
@Test public void testShouldSetUidWhenSystemFlagChange() throws Exception { final long uid = 900L; MyMailboxSession mSession = new MyMailboxSession(11); MyImapSession imapsession = new MyImapSession(mSession); SelectedMailboxImpl analyser = new SelectedMailboxImpl(mockManager, imapsession, mailboxPath); final FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate(new MyMailboxSession(41), Arrays.asList(uid),/* w w w. j a va 2 s . co m*/ Arrays.asList(new UpdatedFlags(uid, -1, new Flags(), new Flags(Flags.Flag.ANSWERED))), mailboxPath); analyser.event(update); final Iterator<Long> iterator = analyser.flagUpdateUids().iterator(); assertNotNull(iterator); assertTrue(iterator.hasNext()); assertEquals(new Long(uid), iterator.next()); assertFalse(iterator.hasNext()); }
From source file:org.apache.james.jmap.methods.integration.SetMessagesMethodTest.java
@Test public void setMessagesShouldMarkAsFlaggedWhenIsFlaggedPassed() throws MailboxException { // Given//from w w w . j ava2 s . c o m jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags()); await(); String presumedMessageId = username + "|mailbox|1"; given().header("Authorization", accessToken.serialize()) .body(String.format( "[[\"setMessages\", {\"update\": {\"%s\" : { \"isFlagged\" : true } } }, \"#0\"]]", presumedMessageId)) // When .when().post("/jmap"); // Then with().header("Authorization", accessToken.serialize()) .body("[[\"getMessages\", {\"ids\": [\"" + presumedMessageId + "\"]}, \"#0\"]]").post("/jmap") .then().log().ifValidationFails().body(NAME, equalTo("messages")) .body(ARGUMENTS + ".list", hasSize(1)).body(ARGUMENTS + ".list[0].isFlagged", equalTo(true)); }
From source file:org.apache.james.imap.processor.base.MailboxEventAnalyserTest.java
@Test public void testShouldClearFlagUidsUponReset() throws Exception { final long uid = 900L; MyMailboxSession mSession = new MyMailboxSession(11); MyImapSession imapsession = new MyImapSession(mSession); SelectedMailboxImpl analyser = new SelectedMailboxImpl(mockManager, imapsession, mailboxPath); final FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate(mSession, Arrays.asList(uid),/*from www. ja va 2 s. c o m*/ Arrays.asList(new UpdatedFlags(uid, -1, new Flags(), new Flags(Flags.Flag.ANSWERED))), mailboxPath); analyser.event(update); analyser.event(update); analyser.deselect(); assertNotNull(analyser.flagUpdateUids()); assertFalse(analyser.flagUpdateUids().iterator().hasNext()); }
From source file:com.sonicle.webtop.mail.Service.java
@Override public void initialize() { ArrayList<String> allFlagsArray = new ArrayList<String>(); for (WebtopFlag fs : webtopFlags) { allFlagsArray.add(fs.label);/*from ww w .ja v a 2s. co m*/ String oldfs = "flag" + fs.label; flagsAll.add(fs.label); //if (fs.tbLabel!=null) tbFlagsAll.add(fs.tbLabel); oldFlagsAll.add(oldfs); Flags flags = new Flags(); flags.add(fs.label); flagsHash.put(fs.label, flags); flags = new Flags(); flags.add(oldfs); oldFlagsHash.put(fs.label, flags); /*if (fs.tbLabel!=null) { Flags tbFlags=new Flags(); tbFlags.add(fs.tbLabel); tbFlagsHash.put(fs.label, tbFlags); }*/ } /*for(WebtopFlag fs: webtopFlags) { if (fs.tbLabel!=null) allFlagsArray.add(fs.tbLabel); }*/ for (WebtopFlag fs : webtopFlags) { allFlagsArray.add("flag" + fs.label); } allFlagStrings = new String[allFlagsArray.size()]; allFlagsArray.toArray(allFlagStrings); this.environment = getEnv(); mailManager = (MailManager) WT.getServiceManager(SERVICE_ID); cus = new CoreUserSettings(getEnv().getProfileId()); UserProfile profile = getEnv().getProfile(); ss = new MailServiceSettings(SERVICE_ID, getEnv().getProfile().getDomainId()); us = new MailUserSettings(profile.getId(), ss); //mprofile = new MailUserProfile(environment,this); mprofile = new MailUserProfile(mailManager, ss, us, profile); String mailUsername = mprofile.getMailUsername(); String mailPassword = mprofile.getMailPassword(); String authorizationId = mailUsername; boolean isImpersonated = profile.getPrincipal().isImpersonated(); String vmailSecret = ss.getNethTopVmailSecret(); if (isImpersonated) { //use sasl rfc impersonate if no vmailSecret if (vmailSecret == null) { //TODO: implement sasl rfc authorization id if possible //session.getProperties().setProperty("mail.imap.sasl.authorizationid", authorizationId); //mailUsername=ss.getAdminUser(); //mailPassword=ss.getAdminPassword(); } else { mailUsername += "*vmail"; mailPassword = vmailSecret; } } mailManager.setSieveConfiguration(mprofile.getMailHost(), ss.getSievePort(), mailUsername, mailPassword); fcProvided = new FolderCache(this, environment); previewBalanceTags = ss.isPreviewBalanceTags(); mainAccount = createAccount(MAIN_ACCOUNT_ID); mainAccount.setFolderPrefix(mprofile.getFolderPrefix()); mainAccount.setProtocol(mprofile.getMailProtocol()); FP.add(FetchProfile.Item.ENVELOPE); FP.add(FetchProfile.Item.FLAGS); FP.add(FetchProfile.Item.CONTENT_INFO); FP.add(UIDFolder.FetchProfileItem.UID); FP.add("Message-ID"); FP.add("X-Priority"); draftsFP.add(FetchProfile.Item.ENVELOPE); draftsFP.add(FetchProfile.Item.FLAGS); draftsFP.add(FetchProfile.Item.CONTENT_INFO); draftsFP.add(UIDFolder.FetchProfileItem.UID); draftsFP.add("Message-ID"); draftsFP.add("X-Priority"); draftsFP.add(HEADER_SONICLE_FROM_DRAFTER); if (hasDmsDocumentArchiving()) { FP.add("X-WT-Archived"); draftsFP.add("X-WT-Archived"); } pecFP.add(FetchProfile.Item.ENVELOPE); pecFP.add(FetchProfile.Item.FLAGS); pecFP.add(FetchProfile.Item.CONTENT_INFO); pecFP.add(UIDFolder.FetchProfileItem.UID); pecFP.add("Message-ID"); pecFP.add("X-Priority"); pecFP.add(HDR_PEC_PROTOCOLLO); pecFP.add(HDR_PEC_RIFERIMENTO_MESSAGE_ID); pecFP.add(HDR_PEC_TRASPORTO); pecFP.add(HDR_PEC_RICEVUTA); pecFP.add(HDR_PEC_TIPORICEVUTA); sortfolders = ss.isSortFolder(); mainAccount.setDifferentDefaultFolder(us.getDefaultFolder()); mainAccount.setMailSession(environment.getSession().getMailSession()); mainAccount.setPort(mprofile.getMailPort()); mainAccount.setHost(mprofile.getMailHost()); mainAccount.setUsername(mprofile.getMailUsername()); mainAccount.setPassword(mprofile.getMailPassword()); mainAccount.setReplyTo(mprofile.getReplyTo()); if (isImpersonated) { if (vmailSecret == null) mainAccount.setSaslRFCImpersonate(mprofile.getMailUsername(), ss.getAdminUser(), ss.getAdminPassword()); else mainAccount.setNethImpersonate(mprofile.getMailUsername(), vmailSecret); } mainAccount.setFolderSent(mprofile.getFolderSent()); mainAccount.setFolderDrafts(mprofile.getFolderDrafts()); mainAccount.setFolderSpam(mprofile.getFolderSpam()); mainAccount.setFolderTrash(mprofile.getFolderTrash()); mainAccount.setFolderArchive(mprofile.getFolderArchive()); //TODO initialize user for first time use //SettingsManager sm = wta.getSettingsManager(); //boolean initUser = LangUtils.value(sm.getUserSetting(profile, "mail", com.sonicle.webtop.Settings.INITIALIZE), false); //if(initUser) initializeUser(profile); mft = new MailFoldersThread(this, environment, mainAccount); mft.setCheckAll(mprofile.isScanAll()); mft.setSleepInbox(mprofile.getScanSeconds()); mft.setSleepCycles(mprofile.getScanCycles()); try { loadTags(); mft.abort(); mainAccount.checkStoreConnected(); //prepare special folders if not existant if (ss.isAutocreateSpecialFolders()) { mainAccount.createSpecialFolders(); } mainAccount.setSkipReplyFolders(new String[] { mainAccount.getFolderDrafts(), mainAccount.getFolderSent(), mainAccount.getFolderSpam(), mainAccount.getFolderTrash(), mainAccount.getFolderArchive() }); mainAccount.setSkipForwardFolders( new String[] { mainAccount.getFolderSpam(), mainAccount.getFolderTrash(), }); mainAccount.loadFoldersCache(mft, false); //if (!mainAccount.getMailSession().getDebug()) mft.start(); vfsmanager = (IVfsManager) WT.getServiceManager("com.sonicle.webtop.vfs"); //cloud uploads goes here registerUploadListener("UploadCloudFile", new OnUploadCloudFile()); if (!profile.getPrincipal().getAuthenticationDomain().getDirUri().getScheme() .equals(LdapNethDirectory.SCHEME)) setSharedSeen(mainAccount, us.isSharedSeen()); //if external archive, initialize account if (ss.isArchivingExternal()) { archiveAccount = createAccount(ARCHIVE_ACCOUNT_ID); //MailStore support dropped for poor imap implementation // //if (ss.getArchivingExternalType().equals("mailstore")) { // String defaultFolder=us.getArchiveExternalUserFolder(); // if (defaultFolder==null || defaultFolder.trim().length()==0) // defaultFolder=profile.getEmailAddress(); // //MailStore produces a strange tree with two times the same account name // archiveAccount.setDifferentDefaultFolder(defaultFolder+"/"+defaultFolder); //} //defaults to WebTop External Archive archiveAccount.setHasInboxFolder(true); //archive copy creates INBOX folder under user archive String defaultFolder = us.getArchiveExternalUserFolder(); if (defaultFolder == null || defaultFolder.trim().length() == 0) defaultFolder = profile.getUserId(); archiveAccount.setDifferentDefaultFolder(defaultFolder); archiveAccount.setFolderPrefix(ss.getArchivingExternalFolderPrefix()); archiveAccount.setProtocol(ss.getArchivingExternalProtocol()); archiveAccount.setMailSession(environment.getSession().getMailSession()); archiveAccount.setPort(ss.getArchivingExternalPort()); archiveAccount.setHost(ss.getArchivingExternalHost()); archiveAccount.setUsername(ss.getArchivingExternalUsername()); archiveAccount.setPassword(ss.getArchivingExternalPassword()); archiveAccount.setFolderSent(mprofile.getFolderSent()); archiveAccount.setFolderDrafts(mprofile.getFolderDrafts()); archiveAccount.setFolderSpam(mprofile.getFolderSpam()); archiveAccount.setFolderTrash(mprofile.getFolderTrash()); archiveAccount.setFolderArchive(mprofile.getFolderArchive()); } //add any configured external account for (ExternalAccount extacc : mailManager.listExternalAccounts()) { String id = extacc.getExternalAccountId().toString(); externalAccountsMap.put(id, extacc); MailAccount acct = createAccount(id); acct.setFolderPrefix(extacc.getFolderPrefix()); acct.setProtocol(extacc.getProtocol()); acct.setMailSession(environment.getSession().getMailSession()); acct.setPort(extacc.getPort()); acct.setHost(extacc.getHost()); acct.setUsername(extacc.getUserName()); acct.setPassword(extacc.getPassword()); acct.setFolderSent(extacc.getFolderSent()); acct.setFolderDrafts(extacc.getFolderDrafts()); acct.setFolderSpam(extacc.getFolderSpam()); acct.setFolderTrash(extacc.getFolderTrash()); acct.setFolderArchive(extacc.getFolderArchive()); acct.setReadOnly(extacc.isReadOnly()); externalAccounts.add(acct); MailFoldersThread xmft = new MailFoldersThread(this, environment, acct); xmft.setInboxOnly(true); acct.setFoldersThread(xmft); acct.checkStoreConnected(); acct.loadFoldersCache(xmft, false); //MFT start postponed to first processGetFavoritesTree } } catch (Exception exc) { Service.logger.error("Exception", exc); } }
From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java
@Test public void getMessageListNestedOperatorsShouldWork() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotSeenNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); ComposedMessageId messageNotSeenFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false, new Flags(Flags.Flag.FLAGGED)); ComposedMessageId messageSeenNotFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false, new Flags(Flags.Flag.SEEN)); ComposedMessageId messageSeenFlagged = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/oneInlinedImage.eml"), new Date(), false, FlagsBuilder.builder().add(Flags.Flag.SEEN, Flags.Flag.FLAGGED).build()); await();/* w w w . j av a 2 s .c o m*/ given().header("Authorization", accessToken.serialize()) .body("[[\"getMessageList\", {\"filter\":{\"operator\":\"OR\",\"conditions\":[" + "{\"operator\":\"AND\", \"conditions\":[{\"isFlagged\":\"true\"},{\"isUnread\":\"true\"}]}," + "{\"operator\":\"AND\", \"conditions\":[{\"isFlagged\":\"true\"},{\"isUnread\":\"false\"}]}" + "]}}, \"#0\"]]") .when().post("/jmap").then().statusCode(200).body(NAME, equalTo("messageList")) .body(ARGUMENTS + ".messageIds", allOf(containsInAnyOrder(messageSeenFlagged.getMessageId().serialize(), messageNotSeenFlagged.getMessageId().serialize()), not(containsInAnyOrder(messageNotSeenNotFlagged.getMessageId().serialize(), messageSeenNotFlagged.getMessageId().serialize())))); }
From source file:org.apache.james.imap.processor.base.MailboxEventAnalyserTest.java
@Test public void testShouldSetUidWhenSystemFlagChangeDifferentSessionInSilentMode() throws Exception { final long uid = 900L; MyMailboxSession mSession = new MyMailboxSession(11); MyImapSession imapsession = new MyImapSession(mSession); SelectedMailboxImpl analyser = new SelectedMailboxImpl(mockManager, imapsession, mailboxPath); final FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate( new MyMailboxSession(BASE_SESSION_ID), Arrays.asList(uid), Arrays.asList(new UpdatedFlags(uid, -1, new Flags(), new Flags(Flags.Flag.ANSWERED))), mailboxPath); analyser.event(update);//from w ww . j a va 2 s . c om analyser.setSilentFlagChanges(true); analyser.event(update); final Iterator<Long> iterator = analyser.flagUpdateUids().iterator(); assertNotNull(iterator); assertTrue(iterator.hasNext()); assertEquals(new Long(uid), iterator.next()); assertFalse(iterator.hasNext()); }
From source file:org.apache.james.jmap.methods.integration.SetMessagesMethodTest.java
@Test public void setMessagesShouldRejectUpdateWhenPropertyHasWrongType() throws MailboxException { jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags()); await();//from www . j a v a2 s .c om String messageId = username + "|mailbox|1"; given().header("Authorization", accessToken.serialize()) .body(String.format( "[[\"setMessages\", {\"update\": {\"%s\" : { \"isUnread\" : \"123\" } } }, \"#0\"]]", messageId)) .when().post("/jmap").then().log().ifValidationFails().statusCode(200) .body(NAME, equalTo("messagesSet")).body(NOT_UPDATED, hasKey(messageId)) .body(NOT_UPDATED + "[\"" + messageId + "\"].type", equalTo("invalidProperties")) .body(NOT_UPDATED + "[\"" + messageId + "\"].properties[0]", equalTo("isUnread")) .body(NOT_UPDATED + "[\"" + messageId + "\"].description", equalTo( "isUnread: Can not construct instance of java.lang.Boolean from String value '123': only \"true\" or \"false\" recognized\n" + " at [Source: {\"isUnread\":\"123\"}; line: 1, column: 2] (through reference chain: org.apache.james.jmap.model.Builder[\"isUnread\"])")) .body(ARGUMENTS + ".updated", hasSize(0)); }