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 Hawat <ha...@gmail.com> on 2013/02/25 11:05:34 UTC
massage the message into a Message (NNTP->MIME)
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: 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