commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thufir Hawat <hawat.thu...@gmail.com>
Subject Re: cannot parse headers to create MIME message
Date Mon, 25 Feb 2013 06:56:46 GMT
On Sun, 24 Feb 2013 23:06:39 +0100, Thomas Neidhart wrote:


> btw. there exists the commons-email component to send mime messages in a
> more convenient way.

I see:

public static MimeMessage createMimeMessage(Session session,
                                            String source)
                                     throws MessagingException,
                                            IOException

This looks promising.  I'm not quite sure how to wire this together with 
http://commons.apache.org/net/examples/nntp/ArticleReader.java which has 
the header and body as seperate String's.

My ArticleReader as so:


package net.bounceme.dur.nntp;

import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.Properties;
import java.util.logging.Logger;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.nntp.NNTPClient;
import org.apache.commons.net.nntp.NewsgroupInfo;

public final class ArticleReader {

    private final static Logger LOG = Logger.getLogger
(ArticleReader.class.getName());
    private String hostname = "localhost";
    private String newsgroup = "comp.lang.java.help";
    private NNTPClient client = new NNTPClient();

    public ArticleReader(Properties p) throws Exception {
        client.addProtocolCommandListener(new PrintCommandListener(new 
PrintWriter(System.out), true));
        client.connect(hostname);
        NewsgroupInfo newsgroupInfo = new NewsgroupInfo();
        client.selectNewsgroup(newsgroup, newsgroupInfo);

        for (long i = newsgroupInfo.getFirstArticleLong(); i < 
newsgroupInfo.getLastArticleLong(); i++) {
            String headers = read(client.retrieveArticleHeader(i));
            String body = read(client.retrieveArticleBody(i));

            //should use createMimeMessage here, or pass to it
            MessageSender mw = new MessageSender(p,headers, body);
        }
    }

    public String read(BufferedReader br) throws Exception {
        StringBuilder lines = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            lines.append(line).append("\n");
        }
        br.close();
        return new String(lines);
    }
}




thanks,

Thufir


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message