Search in sources :

Example 1 with IMAPNestedMessage

use of com.sun.mail.imap.IMAPNestedMessage in project vcell by virtualcell.

the class ListservMail method readMultiPart.

private static void readMultiPart(Multipart mp, int partNum, int size) throws Exception {
    for (int j = 0; j < mp.getCount(); j++) {
        Part part = mp.getBodyPart(j);
        // Enumeration<Header> enumHeaders = part.getAllHeaders();
        // while(enumHeaders.hasMoreElements()){
        // Header h = enumHeaders.nextElement();
        // System.out.println(h.getName()+" "+h.getValue());
        // }
        Object obj = null;
        try {
            obj = part.getContent();
        } catch (UnsupportedEncodingException uce) {
            obj = getStringFromStream(part.getInputStream(), part.getSize());
        }
        if ((obj instanceof IMAPNestedMessage)) {
            readMessage(((IMAPMessage) obj), j, part.getSize());
        } else if (obj instanceof IMAPInputStream) {
            String s = getStringFromStream(((IMAPInputStream) obj), part.getSize());
            System.out.println("stream content= " + s.length() + " " + size + " " + s.contains("@") + " disp=" + part.getDisposition() + " type=" + part.getContentType() + " descr=" + part.getDescription());
        // DataInputStream dis = new DataInputStream(((IMAPInputStream)obj));
        // byte[] bytes = new byte[size];
        // dis.readFully(bytes);
        // String s  = new String(bytes);
        // System.out.println("stream content= "+s.length()+" "+size+" "+s.contains("@")+" disp="+part.getDisposition()+" type="+part.getContentType()+" descr="+part.getDescription());
        // dis.close();
        } else if ((obj instanceof Multipart)) {
            readMultiPart(((Multipart) obj), j, part.getSize());
        } else if ((obj instanceof String)) {
            String s = (String) obj;
            Matcher matcher = pattern.matcher(s);
            while (matcher != null && matcher.find()) {
                MatchResult matchResult = matcher.toMatchResult();
                String email = matchResult.group();
                System.out.println(email);
                bouncedEMails.add(email);
            }
            System.out.println("string content= " + s.length() + " " + size + " " + s.contains("@") + " disp=" + part.getDisposition() + " type=" + part.getContentType() + " descr=" + part.getDescription());
        } else {
            System.out.println("-----TBI part " + partNum + "\n" + obj.getClass().getName());
        }
    }
}
Also used : Multipart(javax.mail.Multipart) Matcher(java.util.regex.Matcher) Part(javax.mail.Part) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IMAPMessage(com.sun.mail.imap.IMAPMessage) IMAPInputStream(com.sun.mail.imap.IMAPInputStream) MatchResult(java.util.regex.MatchResult) IMAPNestedMessage(com.sun.mail.imap.IMAPNestedMessage)

Aggregations

IMAPInputStream (com.sun.mail.imap.IMAPInputStream)1 IMAPMessage (com.sun.mail.imap.IMAPMessage)1 IMAPNestedMessage (com.sun.mail.imap.IMAPNestedMessage)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MatchResult (java.util.regex.MatchResult)1 Matcher (java.util.regex.Matcher)1 Multipart (javax.mail.Multipart)1 Part (javax.mail.Part)1