I have written a DataHandler for multipart/signed messages. However, I am unable to obtain the value of micalg field from the Content-Type header of a Message. How do I get the value of micalg?

Andrea Pompili

You have to extract directly the Content Type Header from the Message and extract it manually (or using the ContentType class):

Example (it's only an example, I don't include error chekings or other):

Message msg = ... (code for generating it);

//Other code...

MimeMessage mimeMsg = (MimeMessage)msg;
String[] all = mimeMsg.getHeader("Content-Type");
String ctype = "";

for (int i = 0; i < all.length; i++) 
  ctype += all[i] + " ";

int idx1 = ctype.indexOf("micalg=");
int idx2 = ctype.indexOf(";", idx1);  
String micalg = ctype.substring(idx1, idx2);
Otherwise you could use the JavaMail API:
//As the above example...

MimeMessage mimeMsg = (MimeMessage)msg;
String ctype = mimeMsg.getHeader("Content-Type", " ");
ContentType ct = new ContentType(ctype);
String micalg = ct.getParameter("micalg");
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact