Example usage for javax.mail.search SearchTerm toString

List of usage examples for javax.mail.search SearchTerm toString

Introduction

In this page you can find the example usage for javax.mail.search SearchTerm toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.jevis.emaildatasource.EmailForTest.java

public void testMail() throws MessagingException {
    List<InputStream> answerList = new ArrayList<InputStream>();

    _userName = "artur.iablokov@envidatec.com";
    _password = "na733aya";
    _host = "imap.1und1.de";

    Properties props = new Properties();
    props.put("mail.debug", "true");
    props.put("mail.store.protocol", "imaps");
    _session = Session.getInstance(props);
    _store = _session.getStore();//ww  w  .  java 2 s  .  c  o  m
    _store.connect(_host, _userName, _password);
    if (!_store.isConnected()) {
        System.out.println("Connected not possible");
    }
    _folderName = "INBOX"; // TODO
    _folder = _store.getFolder(_folderName);
    _folder.open(Folder.READ_ONLY);

    System.out.println("//////////Folder open!/////");

    InputStream answer = null;

    //channel parameter bekommen
    String sender = "support@jevis.de";
    String subject = "testinfo";
    Date lastReadout = new Date(1459658993827L);
    System.out.println("channel parameters: " + sender + " " + subject + " " + lastReadout);
    //richtige E-Mail(-s) finden
    SearchTerm newerThan = new ReceivedDateTerm(ComparisonTerm.GT, lastReadout);
    SearchTerm senderTerm = null;
    try {
        senderTerm = new FromTerm(new InternetAddress(sender));
    } catch (AddressException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    SearchTerm subjectTerm = new SubjectTerm(subject);
    SearchTerm andTerm = new AndTerm(newerThan, new AndTerm(senderTerm, subjectTerm));
    System.out.println(andTerm.toString());
    List<Message> messageList = null;
    try {
        messageList = Arrays.asList(_folder.search(andTerm));
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //
    _folder.close(false);
    System.out.println("Folder closed");
    _store.close();
    System.out.println("Store closed");

    /**
     * List<File> attachments = new ArrayList<File>(); for (Message message
     * : messageList) { try { Multipart multipart = (Multipart)
     * message.getContent(); for (int i = 0; i < multipart.getCount(); i++)
     * { BodyPart bodyPart = multipart.getBodyPart(i); if
     * (!Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition()) &&
     * !StringUtils.isNotBlank(bodyPart.getFileName())) { // !Checks if a
     * String is not empty (""), not null and not whitespace only. continue;
     * // dealing with attachments only } InputStream is =
     * bodyPart.getInputStream(); File file = new File("/tmp/" +
     * bodyPart.getFileName()); FileOutputStream fos = new
     * FileOutputStream(file); byte[] buf = new byte[4096]; int bytesRead;
     * while ((bytesRead = is.read(buf)) != -1) { fos.write(buf, 0,
     * bytesRead); } fos.close(); attachments.add(file);
        }*
     */

    /*for (int i = 0; i < answerList.size(); i++) {
        System.out.print(answerList.get(i).toString());
        }*/
}