Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Serialize a Mail Message

Thread view: 
Elroy - 14 Nov 2005 15:50 GMT
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.
zero - 15 Nov 2005 02:21 GMT
"Elroy" <elroymcgerkin@gmail.com> wrote in news:bn2ef.6480$lb7.74184
@news1.mts.net:

> I'm trying to write an application to construct a multipart mime
> message that uses a signed certificate. This message is to be "posted"
[quoted text clipped - 14 lines]
>
> 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
Elroy - 18 Nov 2005 15:17 GMT
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.

> "Elroy" <elroymcgerkin@gmail.com> wrote in news:bn2ef.6480$lb7.74184
> @news1.mts.net:
[quoted text clipped - 32 lines]
>
> http://www.mindprod.com/jgloss/newsgroups.html#responses 
Chris Uppal - 18 Nov 2005 16:31 GMT
> 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
Elroy - 18 Nov 2005 18:38 GMT
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.

>> I need to be able to construct a secure multipart mime message with
>> custom
[quoted text clipped - 14 lines]
>
>    -- chris
zero - 18 Nov 2005 19:09 GMT
> The following paragraph of that part states that I already have the
> mime body part thing down.
[quoted text clipped - 12 lines]
>
> 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.
Elroy - 18 Nov 2005 19:35 GMT
>> The following paragraph of that part states that I already have the
>> mime body part thing down.
[quoted text clipped - 15 lines]
> 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.

> PS I use the ClassName:methodName() notation to show that it's not a
> static
> method.
zero - 18 Nov 2005 22:24 GMT
> 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?
Roedy Green - 18 Nov 2005 20:16 GMT
On Fri, 18 Nov 2005 16:31:15 -0000, "Chris Uppal"
<chris.uppal@metagnostic.REMOVE-THIS.org> wrote, quoted or indirectly
quoted someone who said :

>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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.