You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Thufir <ha...@gmail.com> on 2013/02/24 20:17:31 UTC
cannot parse headers to create MIME message
No matter how I try to parse NNTP headers into a MIME message I just get
a flurry of errors. Is there a a trick or technique? Also see:
http://stackoverflow.com/questions/15051188/
thanks,
Thufir
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: cannot parse headers to create MIME message
Posted by Thufir Hawat <ha...@gmail.com>.
On Sun, 24 Feb 2013 23:06:39 +0100, Thomas Neidhart wrote:
> Unless you can not specify in more detail what you want to achieve, we
> may not be able to help you.
>
> btw. there exists the commons-email component to send mime messages in a
> more convenient way.
I'll certainly look into that, it may be what I'm looking for. What's
the most convenient way to send NNTP articles as MIME messages?
thanks,
Thufir
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: cannot parse headers to create MIME message
Posted by Thufir <ha...@gmail.com>.
Pardon, allow me to clarify. In the example
http://commons.apache.org/net/examples/nntp/ArticleReader.java/, headers
are extracted as so:
br = client.retrieveArticleHeader(articleNum);
Now, when that information is sent to MessageSender the result is numerous
parse errors. Following the example of ArticleReader from
http://commons.apache.org/net/examples/nntp/ how should the headers be
processed in order to parse correctly as a MIME type message? I'm simply
sending the lines from ArticleReader to MessageSender, which results in
errors. In general, what's the correct approach or technique?
thanks,
Thufir
On Sun, Feb 24, 2013 at 2:06 PM, Thomas Neidhart
<th...@gmail.com>wrote:
> On 02/24/2013 08:17 PM, Thufir wrote:
> > No matter how I try to parse NNTP headers into a MIME message I just get
> > a flurry of errors. Is there a a trick or technique? Also see:
> >
> > http://stackoverflow.com/questions/15051188/
>
> The example on this page is not related at all to any Apache Commons
> component.
>
> The stacktrace of the error also gives you a very detailed description
> of the problem.
>
> Unless you can not specify in more detail what you want to achieve, we
> may not be able to help you.
>
> btw. there exists the commons-email component to send mime messages in a
> more convenient way.
>
> Thomas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
Re: cannot parse headers to create MIME message
Posted by Thufir Hawat <ha...@gmail.com>.
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
Re: massage the message into a Message (NNTP->MIME)
Posted by Siegfried Goeschl <sg...@gmx.at>.
Hi Thufir,
it is not clear (at least to me) what you would like to achieve ... :-)
According to Wikipedia
"NNTP - It resembled the Simple Mail Transfer Protocol (SMTP), but was
tailored for exchanging newsgroup articles."
A simple road map which could help you
+) have a look http://commons.apache.org/email/userguide.html
+) have a look at the test code
at this point you should have a good idea what you can do with commons-email
Regarding headers - if you would like to add custom (aka non-SMTP)
headers you should use the "X-headers" approach (see
http://www.systemnetmail.com/faq/3.3.4.aspx), which are prefixed with a
"X-" to keep SMTP server and clients happy.
Cheers,
Siegfried Goeschl
On 25.02.13 11:05, Thufir Hawat wrote:
> 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.
>
> While it does help, it still seems to bring up the same type of
> MessagingException and merely moves the problem around:
>
> compile:
> run:
> 200 Leafnode NNTP Daemon, version 1.11.8 running at localhost (my fqdn:
> dur.bounceme.net)
> GROUP comp.lang.java.help
> 211 47 3 49 comp.lang.java.help group selected
> HEAD 3
> 221 3 <7e...@googlegroups.com> article
> retrieved - head follows
> BODY 3
> 222 3 <7e...@googlegroups.com> article
> retrieved - body follows
> Exception in thread "main" javax.mail.MessagingException:
> comp.lang.java.help is not an InternetAddress
> at com.sun.mail.smtp.SMTPTransport.sendMessage
> (SMTPTransport.java:1085)
> at net.bounceme.dur.nntp.ArticleReader.<init>
> (ArticleReader.java:44)
> at net.bounceme.dur.nntp.Driver.<init>(Driver.java:13)
> at net.bounceme.dur.nntp.Driver.main(Driver.java:17)
> Java Result: 1
> BUILD SUCCESSFUL (total time: 2 seconds)
>
>
> The problem being that the String representation of headers returned by
> String headers = read(client.retrieveArticleHeader(i));
> seems fundamentally incompatible with any sort of javax.mail.Message, or
> anything related. there must be a way to turn that String of headers
> into legitimate headers for a Message, but how?
>
> I'm quite sure that it's possible to massage the message, if you'll
> forgive me for abusing that quote, into a Message of one variety or
> another. The question is, how? My ArticleReader.java to follow:
>
> package net.bounceme.dur.nntp;
>
> import java.io.BufferedReader;
> import java.io.PrintWriter;
> import java.util.Properties;
> import java.util.logging.Logger;
> import javax.mail.Message.RecipientType;
> import javax.mail.Session;
> import javax.mail.Transport;
> import javax.mail.internet.MimeMessage;
> import org.apache.commons.mail.util.MimeMessageUtils;
> 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());
>
> public ArticleReader(Properties p) throws Exception {
> NNTPClient client = new NNTPClient();
> client.addProtocolCommandListener(new PrintCommandListener(new
> PrintWriter(System.out), true));
> client.connect(p.getProperty("host"));
> NewsgroupInfo newsgroupInfo = new NewsgroupInfo();
> client.selectNewsgroup(p.getProperty("newsgroup"), newsgroupInfo);
>
> Session session = Session.getDefaultInstance(p);
> String protocol = p.getProperty("protocol");
> String host = p.getProperty("host");
> int port = Integer.valueOf(p.getProperty("port"));
> String username = p.getProperty("username");
> String password = p.getProperty("password");
> Transport transport = session.getTransport(protocol);
> transport.connect(host, port, username, password);
>
> for (long i = newsgroupInfo.getFirstArticleLong(); i <
> newsgroupInfo.getLastArticleLong(); i++) {
> String headers = read(client.retrieveArticleHeader(i));
> String body = read(client.retrieveArticleBody(i));
>
> String sb = headers + body;
> MimeMessage message = MimeMessageUtils.createMimeMessage
> (session, sb);
> message.setRecipients(RecipientType.TO, p.getProperty
> ("recipient"));
>
> transport.sendMessage(message, message.getAllRecipients());
> }
> }
>
> 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);
> }
> }
>
>
>
> Any and all suggestions appreciated.
>
>
> thanks,
>
> Thufir
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
massage the message into a Message (NNTP->MIME)
Posted by Thufir Hawat <ha...@gmail.com>.
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.
While it does help, it still seems to bring up the same type of
MessagingException and merely moves the problem around:
compile:
run:
200 Leafnode NNTP Daemon, version 1.11.8 running at localhost (my fqdn:
dur.bounceme.net)
GROUP comp.lang.java.help
211 47 3 49 comp.lang.java.help group selected
HEAD 3
221 3 <7e...@googlegroups.com> article
retrieved - head follows
BODY 3
222 3 <7e...@googlegroups.com> article
retrieved - body follows
Exception in thread "main" javax.mail.MessagingException:
comp.lang.java.help is not an InternetAddress
at com.sun.mail.smtp.SMTPTransport.sendMessage
(SMTPTransport.java:1085)
at net.bounceme.dur.nntp.ArticleReader.<init>
(ArticleReader.java:44)
at net.bounceme.dur.nntp.Driver.<init>(Driver.java:13)
at net.bounceme.dur.nntp.Driver.main(Driver.java:17)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
The problem being that the String representation of headers returned by
String headers = read(client.retrieveArticleHeader(i));
seems fundamentally incompatible with any sort of javax.mail.Message, or
anything related. there must be a way to turn that String of headers
into legitimate headers for a Message, but how?
I'm quite sure that it's possible to massage the message, if you'll
forgive me for abusing that quote, into a Message of one variety or
another. The question is, how? My ArticleReader.java to follow:
package net.bounceme.dur.nntp;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.Properties;
import java.util.logging.Logger;
import javax.mail.Message.RecipientType;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.MimeMessage;
import org.apache.commons.mail.util.MimeMessageUtils;
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());
public ArticleReader(Properties p) throws Exception {
NNTPClient client = new NNTPClient();
client.addProtocolCommandListener(new PrintCommandListener(new
PrintWriter(System.out), true));
client.connect(p.getProperty("host"));
NewsgroupInfo newsgroupInfo = new NewsgroupInfo();
client.selectNewsgroup(p.getProperty("newsgroup"), newsgroupInfo);
Session session = Session.getDefaultInstance(p);
String protocol = p.getProperty("protocol");
String host = p.getProperty("host");
int port = Integer.valueOf(p.getProperty("port"));
String username = p.getProperty("username");
String password = p.getProperty("password");
Transport transport = session.getTransport(protocol);
transport.connect(host, port, username, password);
for (long i = newsgroupInfo.getFirstArticleLong(); i <
newsgroupInfo.getLastArticleLong(); i++) {
String headers = read(client.retrieveArticleHeader(i));
String body = read(client.retrieveArticleBody(i));
String sb = headers + body;
MimeMessage message = MimeMessageUtils.createMimeMessage
(session, sb);
message.setRecipients(RecipientType.TO, p.getProperty
("recipient"));
transport.sendMessage(message, message.getAllRecipients());
}
}
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);
}
}
Any and all suggestions appreciated.
thanks,
Thufir
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: cannot parse headers to create MIME message
Posted by Thomas Neidhart <th...@gmail.com>.
On 02/24/2013 08:17 PM, Thufir wrote:
> No matter how I try to parse NNTP headers into a MIME message I just get
> a flurry of errors. Is there a a trick or technique? Also see:
>
> http://stackoverflow.com/questions/15051188/
The example on this page is not related at all to any Apache Commons
component.
The stacktrace of the error also gives you a very detailed description
of the problem.
Unless you can not specify in more detail what you want to achieve, we
may not be able to help you.
btw. there exists the commons-email component to send mime messages in a
more convenient way.
Thomas
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: cannot parse headers to create MIME message
Posted by Petite Abeille <pe...@me.com>.
On Feb 24, 2013, at 8:17 PM, Thufir <ha...@gmail.com> wrote:
> No matter how I try to parse NNTP headers into a MIME message I just get a flurry of errors. Is there a a trick or technique? Also see:
>
> http://stackoverflow.com/questions/15051188/
^ As far as JavaMail goes, try mail.mime.address.strict = false.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org