Search in sources :

Example 1 with StatusResponseType

use of org.nhindirect.schema.edge.ws.StatusResponseType in project nhin-d by DirectProject.

the class MessageServiceImplService method requestStatus.

@Override
public StatusResponseType requestStatus(StatusRefType body) {
    List<String> msgs = body.getMessageID();
    StatusResponseType response = new StatusResponseType();
    try {
        checkAuth(response);
        Authenticator auth = new SMTPAuthenticator();
        Session session = Session.getInstance(imapProps, auth);
        session.setDebug(true);
        if (msgs.size() > 0) {
            Store store = session.getStore(new javax.mail.URLName("imaps://" + username));
            store.connect(getImapHost(), Integer.valueOf(getImapPort()).intValue(), username, password);
            for (int x = 0; x < msgs.size(); x++) {
                String msgid = msgs.get(x);
                MessageIDTerm messageIdTerm = new MessageIDTerm(msgid);
                IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
                folder.open(Folder.READ_ONLY);
                SearchTerm st = messageIdTerm;
                IMAPMessage[] msgsearch = (IMAPMessage[]) folder.search(st);
                if (msgsearch.length > 0) {
                    Flags flags = msgsearch[0].getFlags();
                    Flag[] inboxflags = flags.getSystemFlags();
                    String[] listofflags = new String[inboxflags.length];
                    listofflags = setSystemFlags(inboxflags);
                    setMessageIdStatus(msgid, listofflags, response.getMessageIDAndStatus());
                }
            }
        }
    } catch (AddressException e) {
        log.error(e);
    } catch (MessagingException e) {
        log.error(e);
    } catch (Exception e) {
        log.error(e);
    }
    return response;
}
Also used : MessageIDTerm(javax.mail.search.MessageIDTerm) MessagingException(javax.mail.MessagingException) IMAPFolder(com.sun.mail.imap.IMAPFolder) Store(javax.mail.Store) Flags(javax.mail.Flags) SearchTerm(javax.mail.search.SearchTerm) Flag(javax.mail.Flags.Flag) StatusResponseType(org.nhindirect.schema.edge.ws.StatusResponseType) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) InvalidPropertyException(org.springframework.beans.InvalidPropertyException) IOException(java.io.IOException) AddressException(javax.mail.internet.AddressException) IMAPMessage(com.sun.mail.imap.IMAPMessage) Authenticator(javax.mail.Authenticator) Session(javax.mail.Session)

Aggregations

IMAPFolder (com.sun.mail.imap.IMAPFolder)1 IMAPMessage (com.sun.mail.imap.IMAPMessage)1 IOException (java.io.IOException)1 Authenticator (javax.mail.Authenticator)1 Flags (javax.mail.Flags)1 Flag (javax.mail.Flags.Flag)1 MessagingException (javax.mail.MessagingException)1 Session (javax.mail.Session)1 Store (javax.mail.Store)1 AddressException (javax.mail.internet.AddressException)1 MessageIDTerm (javax.mail.search.MessageIDTerm)1 SearchTerm (javax.mail.search.SearchTerm)1 StatusResponseType (org.nhindirect.schema.edge.ws.StatusResponseType)1 InvalidPropertyException (org.springframework.beans.InvalidPropertyException)1