Serialize a Mail Message

E

Elroy

I'm trying to write an application to construct a multipart mime
message that uses a signed certificate. This message is to be "posted"
to a particular internet address that is a location of a file server
that is to decrypt the message and process it.

I need to be able to construct the message without actually creating a
session. Really, all I need is the multipart mime and mime bodyparts to
feed into a data stream that I've written to post the message.

I've been trying to debug my app by attempting to serialize the
multipart mime and write it to disk, but my code keeps blowing up.

Is there any particular sequence to follow after signing the multipart
mime to serialize it to a fileoutput stream?

Any help would be appreciated.

Thanks.
 
Z

zero

I'm trying to write an application to construct a multipart mime
message that uses a signed certificate. This message is to be "posted"
to a particular internet address that is a location of a file server
that is to decrypt the message and process it.

I need to be able to construct the message without actually creating a
session. Really, all I need is the multipart mime and mime bodyparts to
feed into a data stream that I've written to post the message.

I've been trying to debug my app by attempting to serialize the
multipart mime and write it to disk, but my code keeps blowing up.

Is there any particular sequence to follow after signing the multipart
mime to serialize it to a fileoutput stream?

Any help would be appreciated.

Thanks.

If your code blows up maybe you should start working for the defense
department.

You didn't post any code, say exactly what goes wrong, show any output,
tell us what products you're using, what your level of expertise is, or
anything that could lead to a solution.

Try reading the following link, and then restate your question.

http://www.catb.org/~esr/faqs/smart-questions.html

or, more specifically for this group:

http://www.mindprod.com/jgloss/newsgroups.html#responses
 
E

Elroy

Ouch...
That's a little harsh...
Unfortunately I can't post any source code due to 2 reasons.
1. I'm using proprietary api's that deal with encryption and certificates
that are written by a company called Entrust.
2. The api's are used to connect to a secure server for a client that I'm
not a liberty to divulge.

That being said, I apologize for the ambiguity, but I'm limited on what I
can say.

So let's try this again.

I need to be able to construct a secure multipart mime message with custom
headers.
I need to be able to sign my multipart parts with a secure signature
I need to be able to modify the multipart part headers to remove and add
specific header lines.
I need to encrypt the multipart parts (again) using pk7 encryption and
stream the encrypted object to an internet server.

I've completed the above tasks with the exception of the 3rd item, modifying
the multipart headers.
The only way I've found to create a header object is to use InternetHeaders
from javax.mail.internet.
I can see the header lines, but I can't get them out of the Enumeration
object.

eg. InternetHeaders hedr = new InternetHeaders();
Vector headlines;
Enumeration henum = hedr.getAllHeaderLines();
while(henum.hasMoreElements())
{
headlines.add(henum.nextElement())
}
That's what blows up.
(well not exactly, it just returns null)

So if you have any advice on how to manipulate message headers or know of
any resources out there that I can read to educate myself, I would greatly
appreciate it.
If anyone has done development with the Entrust encryption software that
uses posting of s/mime messages to an internet server and has some tips to
share, please contact me via my gmail address.

and yes... I've googled the snot out of this one.
 
C

Chris Uppal

Elroy said:
I need to be able to construct a secure multipart mime message with custom
headers.
I need to be able to sign my multipart parts with a secure signature
I need to be able to modify the multipart part headers to remove and add
specific header lines.

At the risk of looking stupid (since I know almost nothing about the Java mail
APIs), what sort of objects are you manipulating here ? At first glance it
looks as if you will be creating a MimeMessage with a 'content' that is a
MimeMulitpart with zero or more 'body parts' each of which is a MimeModyPart.
If so, then there are plenty of methods defined against MimeModyPart for
manipulating headers.

-- chris
 
E

Elroy

The following paragraph of that part states that I already have the mime
body part thing down.

"I've completed the above tasks with the exception of the 3rd item,
modifying
the multipart headers."

I'm attempting to manipulate a header object and change it's header lines.

Do you know of the best way to retrieve an array of strings from an
InternetHeaders object?
The only method offered is dumping the object to an Enumeration, but then
what? I can't access the elements in the enumeration.

I'm at a loss on that.
 
Z

zero

Elroy said:
The following paragraph of that part states that I already have the
mime body part thing down.

"I've completed the above tasks with the exception of the 3rd item,
modifying
the multipart headers."

I'm attempting to manipulate a header object and change it's header
lines.

Do you know of the best way to retrieve an array of strings from an
InternetHeaders object?
The only method offered is dumping the object to an Enumeration, but
then what? I can't access the elements in the enumeration.

I'm at a loss on that.

Have you tried printing the Enumeration to System.out, to see if there's
actually anything in there? It could be it's just full of null objects.

Btw note that InternetHeaders:getAllHeaders() returns an Enumeration of
Header objects, NOT an Enumeration of Strings. You may do better with
InternetHeaders:getAllHeaderLines();

In either case I'd suggest trying to narrow down the problem by using lots
and lots of System.out.print statements (or use an IDE's debugger) to check
the contents of every object at every stage in the program's execution.

PS I use the ClassName:methodName() notation to show that it's not a static
method.
 
E

Elroy

zero said:
Have you tried printing the Enumeration to System.out, to see if there's
actually anything in there? It could be it's just full of null objects.

I'm using Netbeans 4.1 to debug the project (free and not bad for an IDE)

The local variables window indicates there are 21 Vector elements to the
InternetHeaders object that I create

InternetHeaders hedr = new InternetHeaders();


Btw note that InternetHeaders:getAllHeaders() returns an Enumeration of
Header objects, NOT an Enumeration of Strings. You may do better with
InternetHeaders:getAllHeaderLines();

original code....

Enumeration henum = hedr.getAllHeaderLines();

I've tried to cast that puppy too. no luck.
In either case I'd suggest trying to narrow down the problem by using lots
and lots of System.out.print statements (or use an IDE's debugger) to
check
the contents of every object at every stage in the program's execution.
I'm using breakpoints in the netbeans ide. Works pretty slick.
I've also been able to use Oracles JDeveloper to debug as well, but it's a
bit more of a pig on system resources. Same issue.
 
R

Roedy Green

At the risk of looking stupid (since I know almost nothing about the Java mail
APIs), what sort of objects are you manipulating here ? At first glance it
looks as if you will be creating a MimeMessage with a 'content' that is a
MimeMulitpart with zero or more 'body parts' each of which is a MimeModyPart.
If so, then there are plenty of methods defined against MimeModyPart for
manipulating headers.

you have classes coming out your ears.

to read and write a single message you will likely need the following
classes:

import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Properties;

import javax.mail.Address;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

see http://mindprod.com/jgloss/javamail.html

Look at the tutorials and sample code. The JavaDoc is hopeless for
explaining how you fit it all together.
 
Z

zero

The local variables window indicates there are 21 Vector elements to
the InternetHeaders object that I create

what about the Enumeration? Does it have any objects, and are they not
null?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top