Class SMimeBodyPart

  extended by javax.mail.BodyPart
      extended by javax.mail.internet.MimeBodyPart
          extended by iaik.smime.SMimeBodyPart
All Implemented Interfaces:
javax.mail.internet.MimePart, javax.mail.Part

public class SMimeBodyPart
extends javax.mail.internet.MimeBodyPart

This class extends the standard MimeBodyPart class of the javax.mail.internet package about MessageDigest calculation.

This class shall used when creating a body part to be sent within a multipart/signed message. When using the parent MimeBodyPart class no canonicalization is performed.

Field Summary
Fields inherited from class javax.mail.internet.MimeBodyPart
content, contentStream, dh, headers
Fields inherited from class javax.mail.BodyPart
Fields inherited from interface javax.mail.Part
Constructor Summary
          Creates a new SMimeBodyPart.
SMimeBodyPart(javax.mail.internet.InternetHeaders headers, byte[] content)
          Creates a new SMimeBodyPart from given header and content bytes.
Method Summary
 void checkForSMimeParts(boolean checkForSMimeParts)
          Turns on/off control to use SMimeMultiparts and SMimeBodyParts insteadof MimeMultipatrs and MimeBodyParts when supplying the content for this SMimeBodyPart.
 void setDataHandler(javax.activation.DataHandler dh)
          Sets the content wrapped by a javax.activation.DataHandler.
 void writeTo(java.io.OutputStream os)
          Writes the body part as an RFC 822 formatted stream and calculates a message digest over the data.
Methods inherited from class javax.mail.internet.MimeBodyPart
addHeader, addHeaderLine, getAllHeaderLines, getAllHeaders, getContent, getContentID, getContentLanguage, getContentMD5, getContentStream, getContentType, getDataHandler, getDescription, getDisposition, getEncoding, getFileName, getHeader, getHeader, getInputStream, getLineCount, getMatchingHeaderLines, getMatchingHeaders, getNonMatchingHeaderLines, getNonMatchingHeaders, getRawInputStream, getSize, isMimeType, removeHeader, setContent, setContent, setContentLanguage, setContentMD5, setDescription, setDescription, setDisposition, setFileName, setHeader, setText, setText, updateHeaders
Methods inherited from class javax.mail.BodyPart
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public SMimeBodyPart()
Creates a new SMimeBodyPart.


public SMimeBodyPart(javax.mail.internet.InternetHeaders headers,
                     byte[] content)
              throws javax.mail.MessagingException
Creates a new SMimeBodyPart from given header and content bytes.

headers - the headers
content - bytes representing the body of this part.
javax.mail.MessagingException - if an error occurs when creating this body part
Method Detail


public void checkForSMimeParts(boolean checkForSMimeParts)
Turns on/off control to use SMimeMultiparts and SMimeBodyParts insteadof MimeMultipatrs and MimeBodyParts when supplying the content for this SMimeBodyPart. Especially when creating a signed message of type multipart/signed ("clear-signed") care has to be taken to properly canonicalize -- in particular text -- messages to give the same unique representation on the sender side where the signature is created and on the recipient side where the signature is verified.
The content of a signed message may be composed of MimeMultiparts consiting theirselves of several MimeBodyParts. To ensure that these body parts are canonicalized, they have to be modelled as SMimeBodyPart objects rather than using plain MimeBodyParts. When building a multipart entity from several body parts, the SMimeBodyParts have to be inserted into a SMimeMultipart object instead of using a plain MimeMultipart.
To avoid verification problems due to usage of not canonicalized parts, IAIK-CMS by default checks if SMimeMultiparts and SMimeBodyParts are used when creating a signed message. An exception is thrown if only plain MimeBodyParts and MimeMultiparts are used. However, when signing an already canonicalized entity (e.g. the content of a message just parsed) this check for SMimeMultiparts/SMimeBodyParts may not be required. In this case it might give some processing overhead to convert any MimeMultipart and MimeBodyPart to the required SMimeMultipart respectively SMimeBodyPart. For that reason it is possible to turn off the SMimePart check for a particular SignedContent, SMimeMultipart and/or SMimeBodyPart object or generally disable the SMimeBodyPart check throughout the whole application environment. When choosing the latter option by calling
take care to continue to use SMimeBodyParts and SMimeMultiparts when signing a newly created yet not canoinicalized content.

checkForSMimeParts - whether to turn on/off SMimePart checking


public void setDataHandler(javax.activation.DataHandler dh)
                    throws javax.mail.MessagingException
Sets the content wrapped by a javax.activation.DataHandler.

Specified by:
setDataHandler in interface javax.mail.Part
setDataHandler in class javax.mail.internet.MimeBodyPart
dh - the dataHandler wrapping the content
javax.mail.MessagingException - if the content supplied by the DataHandler cannot be accessed or the content represents a Multipart but is not supplied as SMimeMultipart (in the case of SMimePart control is enabled)


public void writeTo(java.io.OutputStream os)
             throws java.io.IOException,
Writes the body part as an RFC 822 formatted stream and calculates a message digest over the data.

The message digest is set for the inherent JMailSMimeSigned object to be written as next part of the multipart/signed.

Specified by:
writeTo in interface javax.mail.Part
writeTo in class javax.mail.internet.MimeBodyPart
os - the output stream where the content shall be written to
java.io.IOException - if an error occurs while writing to the stream
javax.mail.MessagingException - if an mail related error occurs

This Javadoc may contain text parts from text parts from IETF Internet Standard specifications (see copyright note).

IAIK-CMS 6.0, (c) 2002 IAIK, (c) 2003, 2023 SIC