You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-user@james.apache.org by "bill.damage" <bi...@yahoo.com> on 2008/08/12 15:22:39 UTC

Need to get the raw email

Hi, 

In a Mailets service method I see the param is a Mail instance. I need to
get the full raw email from this, that is all the headers, subject, body etc
actually as transmitted. How is this done please? 

Thanks.

-- Bill
-- 
View this message in context: http://www.nabble.com/Need-to-get-the-raw-email-tp18944186p18944186.html
Sent from the James - Users mailing list archive at Nabble.com.


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


Re: Need to get the raw email

Posted by Sascha Fröhlich <sa...@gmail.com>.
bill.damage schrieb:
> 
> 
> Am Dienstag, den 12.08.2008, 07:00 -0700 schrieb bill.damage:
>>
>> Stefano Bagnara-2 wrote:
>>> bill.damage ha scritto:
>>>> Hi, 
> 
> Hey sincere thanks for all the help but I'm still not there. I hope I
> implemented your code correctly, but here rawEmail always comes out as "":
> 
> 	public void service(Mail mail) throws MessagingException {
> 
> 		logger.info("Entering Mailet service method");
> 		MimeMessage message = mail.getMessage();
>    	    String rawEmail = "";
> 	  
> 	    StringBuffer sb = new StringBuffer();
> 	    try {
>    	        BufferedReader msgStream = new BufferedReader(
> 	            new InputStreamReader(message.getInputStream()));
> 	        String line = null;
> 
> 	        while ((line = msgStream.readLine()) != null) {
> 	            sb.append(line);
> 	        }
> 	    } catch (Exception e) {
> 	    	logger.log(Level.SEVERE, e.getMessage(), e);
> 	    }
> 
> 	    rawEmail = sb.toString();  
> ...
> 

You can use the writeTo function from MimeMessage as mentioned before 
and described here: 
http://java.sun.com/products/javamail/javadocs/javax/mail/internet/MimeMessage.html#writeTo(java.io.OutputStream)

Its a lot easier :-)

Regards,
Sascha F.

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


Re: Need to get the raw email

Posted by "bill.damage" <bi...@yahoo.com>.


Am Dienstag, den 12.08.2008, 07:00 -0700 schrieb bill.damage:
> 
> 
> Stefano Bagnara-2 wrote:
> > 
> > bill.damage ha scritto:
> >> Hi, 

Hey sincere thanks for all the help but I'm still not there. I hope I
implemented your code correctly, but here rawEmail always comes out as "":

	public void service(Mail mail) throws MessagingException {

		logger.info("Entering Mailet service method");
		MimeMessage message = mail.getMessage();
   	    String rawEmail = "";
	  
	    StringBuffer sb = new StringBuffer();
	    try {
   	        BufferedReader msgStream = new BufferedReader(
	            new InputStreamReader(message.getInputStream()));
	        String line = null;

	        while ((line = msgStream.readLine()) != null) {
	            sb.append(line);
	        }
	    } catch (Exception e) {
	    	logger.log(Level.SEVERE, e.getMessage(), e);
	    }

	    rawEmail = sb.toString();  
...


-- 
View this message in context: http://www.nabble.com/Need-to-get-the-raw-email-tp18944186p18945742.html
Sent from the James - Users mailing list archive at Nabble.com.


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


Re: Need to get the raw email

Posted by Norman Maurer <no...@apache.org>.
Am Dienstag, den 12.08.2008, 07:00 -0700 schrieb bill.damage:
> 
> 
> Stefano Bagnara-2 wrote:
> > 
> > bill.damage ha scritto:
> >> Hi, 
> >> 
> >> In a Mailets service method I see the param is a Mail instance. I need to
> >> get the full raw email from this, that is all the headers, subject, body
> >> etc
> >> actually as transmitted. How is this done please? 
> >> 
> >> Thanks.
> > 
> > Mail.getMessage()
> > 
> > Thanks - that returns a javax.mail.internet.MimeMessage - I can't quite
> > see how to get the String of the raw email from it?
> > Stefano
> > 
> > 
Something like this:

BufferedReader msgStream = new BufferedReader(new InputStreamReader(MimeMessage.getInputStream());
String line = null;
StringBuffer sb = new StringBuffer();

while ((line = msgStream.readLine()) != null) {
	sb.append(line);
}

System.out.println(sb.toString());

Cheers,
Norman



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


Re: Need to get the raw email

Posted by Stefano Bagnara <ap...@bago.org>.
bill.damage ha scritto:
> Stefano Bagnara-2 wrote:
>> bill.damage ha scritto:
>>> Hi, 
>>>
>>> In a Mailets service method I see the param is a Mail instance. I need to
>>> get the full raw email from this, that is all the headers, subject, body
>>> etc
>>> actually as transmitted. How is this done please? 
>>>
>>> Thanks.
>> Mail.getMessage()
>>
> Thanks - that returns a javax.mail.internet.MimeMessage - I can't quite
> see how to get the String of the raw email from it?
> Stefano

You should look at javamail documentation for that.

One solution is to use:
-------
ByteArrayOutpuStream bos = new ByteArrayOutputStream();
Mail.getMessage().writeTo(bos);
-----
Then you can use a ByteArrayInputStream to read that data.

Please note that this method dump the whole message in memory, so make 
sure you don't do this with big messages.

Stefano

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


Re: Need to get the raw email

Posted by "bill.damage" <bi...@yahoo.com>.


Stefano Bagnara-2 wrote:
> 
> bill.damage ha scritto:
>> Hi, 
>> 
>> In a Mailets service method I see the param is a Mail instance. I need to
>> get the full raw email from this, that is all the headers, subject, body
>> etc
>> actually as transmitted. How is this done please? 
>> 
>> Thanks.
> 
> Mail.getMessage()
> 
> Thanks - that returns a javax.mail.internet.MimeMessage - I can't quite
> see how to get the String of the raw email from it?
> Stefano
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
> For additional commands, e-mail: server-user-help@james.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Need-to-get-the-raw-email-tp18944186p18944853.html
Sent from the James - Users mailing list archive at Nabble.com.


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


Re: Need to get the raw email

Posted by Stefano Bagnara <ap...@bago.org>.
bill.damage ha scritto:
> Hi, 
> 
> In a Mailets service method I see the param is a Mail instance. I need to
> get the full raw email from this, that is all the headers, subject, body etc
> actually as transmitted. How is this done please? 
> 
> Thanks.

Mail.getMessage()

Stefano


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