Example usage for javax.mail Flags add

List of usage examples for javax.mail Flags add

Introduction

In this page you can find the example usage for javax.mail Flags add.

Prototype

public void add(Flags f) 

Source Link

Document

Add all the flags in the given Flags object to this Flags object.

Usage

From source file:com.hs.mail.imap.dao.FlagUtils.java

static Flags getFlags(ResultSet rs) throws SQLException {
    Flags flags = new Flags();
    for (int i = 0; i < attrArray.length; i++) {
        if ("Y".equals(rs.getString(attrArray[i]))) {
            flags.add(flagArray[i]);
        }//  w  ww  .  j  a  v  a2  s.  com
    }
    return flags;
}

From source file:com.hs.mail.imap.dao.MySqlMessageDao.java

public FetchData getMessageFetchData(long messageID) {
    String sql = "SELECT * FROM message m, physmessage p WHERE m.messageid = ? AND m.physmessageid = p.id";
    FetchData fd = (FetchData) queryForObject(sql, new Object[] { new Long(messageID) }, fetchDataRowMapper);
    if (fd != null) {
        List<String> ufs = getUserFlags(messageID);
        if (CollectionUtils.isNotEmpty(ufs)) {
            Flags flags = fd.getFlags();
            for (String uf : ufs) {
                flags.add(uf);
            }/*  w w  w .  j av  a 2s  . c  o m*/
        }
    }
    return fd;
}

From source file:com.hs.mail.imap.dao.MySqlMessageDao.java

public Flags getFlags(long messageID) {
    Flags flags = getSystemFlags(messageID);
    if (flags == null) {
        flags = new Flags();
    }//  w w  w  . j  av a 2  s . c om
    List<String> ufs = getUserFlags(messageID);
    if (CollectionUtils.isNotEmpty(ufs)) {
        for (String uf : ufs) {
            flags.add(uf);
        }
    }
    return flags;
}

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);/*www  . j  a  va  2 s . c om*/
        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.alfresco.repo.imap.AlfrescoImapFolder.java

/**
 * Moves the node <code>sourceNodeRef</code> extracted from the message id.
 * A part of a complex move operation.//from   w ww . ja va  2  s. c  o m
 * 
 * @param folderInfo FileInfo
 * @param message MimeMessage
 * @param flags Flags
 * @param sourceNodeRef NodeRef
 * @return UUID of the moved node
 * @throws FileExistsException
 * @throws FileNotFoundException
 */
@SuppressWarnings("deprecation")
private long copyOrMoveNode(FileInfo folderInfo, MimeMessage message, Flags flags, NodeRef sourceNodeRef,
        boolean move) throws FileExistsException, FileNotFoundException {
    FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
    FileFilterMode.setClient(FileFilterMode.Client.imap);
    FileInfo messageFile = null;
    if (move) {
        fileFolderService.setHidden(sourceNodeRef, false);
        messageFile = fileFolderService.move(sourceNodeRef, folderInfo.getNodeRef(), null);
    } else {
        NodeRef newNodeRef = serviceRegistry.getCopyService().copyAndRename(sourceNodeRef,
                folderInfo.getNodeRef(), ContentModel.ASSOC_CONTAINS, null, false);
        fileFolderService.setHidden(newNodeRef, false);
        messageFile = fileFolderService.getFileInfo(newNodeRef);
    }
    final long newMessageUid = (Long) messageFile.getProperties().get(ContentModel.PROP_NODE_DBID);

    imapService.persistMessageHeaders(messageFile.getNodeRef(), message);

    Flags newFlags = new Flags(flags);
    newFlags.add(Flag.RECENT);

    imapService.setFlags(messageFile, newFlags, true);
    imapService.setFlag(messageFile, Flag.DELETED, false);

    return newMessageUid;
}

From source file:org.alfresco.repo.imap.AlfrescoImapFolder.java

/**
 *  Creates the EML message in the specified folder.
 *  /* w  w  w . j  ava 2s  .  com*/
 *  @param folderFileInfo The folder to create message in.
 *  @param message The original MimeMessage.
 *  @return ID of the new message created 
 * @throws FileNotFoundException 
 * @throws FileExistsException 
 * @throws MessagingException 
 * @throws IOException 
 */
private long createMimeMessageInFolder(FileInfo folderFileInfo, MimeMessage message, Flags flags)
        throws FileExistsException, FileNotFoundException, IOException, MessagingException {
    String name = AlfrescoImapConst.MESSAGE_PREFIX + GUID.generate();
    FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
    FileInfo messageFile = fileFolderService.create(folderFileInfo.getNodeRef(), name,
            ContentModel.TYPE_CONTENT);
    final long newMessageUid = (Long) messageFile.getProperties().get(ContentModel.PROP_NODE_DBID);
    name = AlfrescoImapConst.MESSAGE_PREFIX + newMessageUid + AlfrescoImapConst.EML_EXTENSION;
    fileFolderService.rename(messageFile.getNodeRef(), name);
    Flags newFlags = new Flags(flags);
    newFlags.add(Flag.RECENT);
    imapService.setFlags(messageFile, newFlags, true);

    if (extractAttachmentsEnabled) {
        imapService.extractAttachments(messageFile.getNodeRef(), message);
    }
    // Force persistence of the message to the repository
    new IncomingImapMessage(messageFile, serviceRegistry, message);
    return newMessageUid;
}

From source file:org.alfresco.repo.imap.ImapServiceImpl.java

/**
 * Return flags that belong to the specified imap folder.
 * /* w  w w.j a  v  a  2s.c  o m*/
 * @param messageInfo imap folder info.
 * @return flags.
 */
public Flags getFlags(FileInfo messageInfo) {
    Flags flags = new Flags();
    Map<QName, Serializable> props = nodeService.getProperties(messageInfo.getNodeRef());

    for (QName key : qNameToFlag.keySet()) {
        Boolean value = (Boolean) props.get(key);
        if (value != null && value) {
            flags.add(qNameToFlag.get(key));
        }
    }

    return flags;
}

From source file:org.apache.hupa.server.handler.SetFlagsHandler.java

@Override
protected GenericResult executeInternal(SetFlag action, ExecutionContext context) throws ActionException {
    User user = getUser();/*from  www .  j  ava2 s.c  o m*/
    IMAPFolder folder = action.getFolder();
    ArrayList<Long> uids = action.getUids();
    com.sun.mail.imap.IMAPFolder f = null;
    try {
        IMAPStore store = cache.get(user);

        f = (com.sun.mail.imap.IMAPFolder) store.getFolder(folder.getFullName());
        if (f.isOpen() == false) {
            f.open(Folder.READ_WRITE);
        }
        Message[] msgs = f.getMessagesByUID(toArray(uids));
        Flag flag = JavamailUtil.convert(action.getFlag());
        Flags flags = new Flags();
        flags.add(flag);

        f.setFlags(msgs, flags, action.getValue());
        return new GenericResult();
    } catch (MessagingException e) {
        String errorMsg = "Error while setting flags of messages with uids " + uids + " for user " + user;
        logger.error(errorMsg, e);
        throw new ActionException(errorMsg, e);
    } finally {
        if (f != null && f.isOpen()) {
            try {
                f.close(false);
            } catch (MessagingException e) {
                // ignore on close
            }
        }
    }
}

From source file:org.apache.james.jmap.model.MailboxMessageTest.java

@Test
public void flagsShouldBeSetIntoMessage() throws Exception {
    Flags flags = new Flags();
    flags.add(Flag.ANSWERED);
    flags.add(Flag.FLAGGED);//w w  w .  j av  a  2s.c o  m
    flags.add(Flag.DRAFT);
    MailboxMessage testMail = new SimpleMailboxMessage(INTERNAL_DATE, 0, 0,
            new SharedByteArrayInputStream("".getBytes()), flags, new PropertyBuilder(), MAILBOX_ID);
    testMail.setModSeq(MOD_SEQ);
    Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(),
            x -> MessageId.of("user|box|" + x));
    assertThat(testee)
            .extracting(Message::isIsUnread, Message::isIsFlagged, Message::isIsAnswered, Message::isIsDraft)
            .containsExactly(true, true, true, true);
}

From source file:org.apache.james.jmap.model.MessageFactoryTest.java

@Test
public void flagsShouldBeSetIntoMessage() throws Exception {
    Flags flags = new Flags();
    flags.add(Flag.ANSWERED);
    flags.add(Flag.FLAGGED);//from  w ww .  j a  v a2  s  .co  m
    flags.add(Flag.DRAFT);
    MetaDataWithContent testMail = MetaDataWithContent.builder().uid(2).flags(flags).size(0)
            .internalDate(INTERNAL_DATE).content(new ByteArrayInputStream("".getBytes(Charsets.UTF_8)))
            .attachments(ImmutableList.of()).mailboxId(MAILBOX_ID).messageId(MessageId.of("test|test|2"))
            .build();
    Message testee = messageFactory.fromMetaDataWithContent(testMail);
    assertThat(testee)
            .extracting(Message::isIsUnread, Message::isIsFlagged, Message::isIsAnswered, Message::isIsDraft)
            .containsExactly(true, true, true, true);
}