Package javax.mail

Examples of javax.mail.Store


    public void generate()
    throws SAXException, ProcessingException {
   
        try {
            Session sess = Session.getDefaultInstance(this.props, null);
            Store st = sess.getStore("imap");

            AttributesImpl attr = new AttributesImpl();

            log("Connecting to IMAP server @ " + this.host);
            st.connect(this.host, this.user, this.pass);

            log("Attempting to open default folder");
            Folder f = st.getFolder("inbox");

            f.open(Folder.READ_WRITE);

            log("Downloading message list from folder");
            this.message = f.getMessages();
View Full Code Here


*/
public class JavaMailConnection extends JavaMailSenderImpl {

    public Folder getFolder(String protocol, String folderName) {
        try {
            Store store = getSession().getStore(protocol);
            store.connect(getHost(), getPort(), getUsername(), getPassword());
            return store.getFolder(folderName);
        } catch (MessagingException e) {
            throw new MailSendException("Mail server connection failed", e);
        }
    }
View Full Code Here

      // Get session
      Session session = Session.getDefaultInstance(props, null);

      // Get the store
      Store store = session.getStore(getServerType());
      store.connect(getServer(), getUserName(), getPassword());

      // Get folder
      Folder folder = store.getFolder(getFolder());
      if (deleteMessages) {
          folder.open(Folder.READ_WRITE);
      } else {
          folder.open(Folder.READ_ONLY);
      }

      // Get directory
      Message messages[] = folder.getMessages();
      Message message;
      StringBuffer pdata = new StringBuffer();
      pdata.append(messages.length);
      pdata.append(" messages found\n");

      int n = getNumMessages();
      if (n == ALL_MESSAGES || n > messages.length) {
        n = messages.length;
      }

      for (int i = 0; i < n; i++) {
              StringBuffer cdata = new StringBuffer();
          SampleResult child = new SampleResult();
          child.sampleStart();
        message = messages[i];

        //if (i == 0)
        { // Assumes all the messaged have the same type ...
            child.setContentType(message.getContentType());
        }

        cdata.append("Message "); // $NON-NLS-1$
        cdata.append(message.getMessageNumber());
        child.setSampleLabel(cdata.toString());
        child.setSamplerData(cdata.toString());
        cdata.setLength(0);
       
        cdata.append("Date: "); // $NON-NLS-1$
        cdata.append(message.getSentDate());
        cdata.append(NEW_LINE);

        cdata.append("To: "); // $NON-NLS-1$
        Address[] recips = message.getAllRecipients();
        for (int j = 0; j < recips.length; j++) {
          cdata.append(recips[j].toString());
          if (j < recips.length - 1) {
            cdata.append("; "); // $NON-NLS-1$
          }
        }
        cdata.append(NEW_LINE);

        cdata.append("From: "); // $NON-NLS-1$
        Address[] from = message.getFrom();
        for (int j = 0; j < from.length; j++) {
          cdata.append(from[j].toString());
          if (j < from.length - 1) {
            cdata.append("; "); // $NON-NLS-1$
          }
        }
        cdata.append(NEW_LINE);

        cdata.append("Subject: "); // $NON-NLS-1$
        cdata.append(message.getSubject());
        cdata.append(NEW_LINE);
       
        cdata.append(NEW_LINE);
        Object content = message.getContent();
        if (content instanceof MimeMultipart) {
          MimeMultipart mmp = (MimeMultipart) content;
          int count = mmp.getCount();
          cdata.append("Multipart. Count: ");
          cdata.append(count);
          cdata.append(NEW_LINE);
          for (int j=0; j<count;j++){
            BodyPart bodyPart = mmp.getBodyPart(j);
            cdata.append("Type: ");
            cdata.append(bodyPart.getContentType());
            cdata.append(NEW_LINE);
            try {
              cdata.append(bodyPart.getContent());
            } catch (UnsupportedEncodingException ex){
              cdata.append(ex.getLocalizedMessage());
            }
            cdata.append(NEW_LINE);
          }
        } else {
            cdata.append(content);
          cdata.append(NEW_LINE);
        }

        if (deleteMessages) {
          message.setFlag(Flags.Flag.DELETED, true);
        }
              child.setResponseData(cdata.toString().getBytes());
              child.setDataType(SampleResult.TEXT);
              child.setResponseCodeOK();
              child.setResponseMessage("OK"); // $NON-NLS-1$
              child.setSuccessful(true);
              child.sampleEnd();
              parent.addSubResult(child);
      }

      // Close connection
      folder.close(true);
      store.close();

      /*
       * Set up the sample result details
       */
      parent.setResponseData(pdata.toString().getBytes());
 
View Full Code Here

    @Override
    public List<GmailMessage> getUnreadMessages() {
        try {
            final List<GmailMessage> unread = new ArrayList<GmailMessage>();
            final Store store = openGmailStore();
            final Folder folder = getFolder(this.srcFolder,store);
            folder.open(Folder.READ_ONLY);
            for (final Message msg : folder.search(new FlagTerm(
                    new Flags(Flags.Flag.SEEN), false))) {
                unread.add(new JavaMailGmailMessage(msg));
View Full Code Here

            return;
        }
        Folder folder = null;
       
        try {
            final Store store = openGmailStore();
            folder = getFolder(this.srcFolder,store);
            if(!folder.isOpen())
            {
                folder.open(Folder.READ_WRITE);               
            }
View Full Code Here

                    + "GmailMessage number");
        }
        Folder folder = null;
       
        try {
            final Store store = openGmailStore();
            folder = getFolder(this.srcFolder, store);
            folder.open(Folder.READ_WRITE);
            Message message = folder.getMessage(messageNumber);
            if (!message.isSet(Flags.Flag.SEEN)) {
                message.setFlag(Flags.Flag.SEEN, true);
View Full Code Here

     */
    public void markAllAsRead() {
        Folder folder = null;

        try {
            final Store store = openGmailStore();
            folder = getFolder(this.srcFolder, store);
            folder.open(Folder.READ_WRITE);
            for (final Message message : folder.search(new FlagTerm(
                    new Flags(Flags.Flag.SEEN), false))) {
                message.setFlag(Flags.Flag.SEEN, true);
View Full Code Here

                    + "GmailMessage number");
        }
        Folder folder = null;

        try {
            final Store store = openGmailStore();
            folder = getFolder(this.srcFolder, store);
            folder.open(Folder.READ_WRITE);
            Message message = folder.getMessage(messageNumber);
            if (message.isSet(Flags.Flag.SEEN)) {
                message.setFlag(Flags.Flag.SEEN, false);
View Full Code Here

                    + "GmailMessage number");
        }
        Folder folder = null;

        try {
            final Store store = openGmailStore();
            folder = getFolder(this.srcFolder, store);
            folder.open(Folder.READ_WRITE);
            Message message = folder.getMessage(messageNumber);
            if (!message.isSet(Flags.Flag.FLAGGED)) {
                message.setFlag(Flags.Flag.FLAGGED, true);
View Full Code Here

                    + "GmailMessage number");
        }
        Folder folder = null;

        try {
            final Store store = openGmailStore();
            folder = getFolder(ImapGmailLabel.STARRED.getName(), store);
            folder.open(Folder.READ_WRITE);
            Message message = folder.getMessage(messageNumber);
            if (message.isSet(Flags.Flag.FLAGGED)) {
                message.setFlag(Flags.Flag.FLAGGED, false);
View Full Code Here

TOP

Related Classes of javax.mail.Store

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.