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?
Created May 4, 2012
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):
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");