|
16 | 16 |
|
17 | 17 | package jakarta.mail.internet; |
18 | 18 |
|
19 | | -import jakarta.mail.*; |
20 | | -import jakarta.activation.*; |
21 | | -import java.io.*; |
22 | | -import java.util.*; |
23 | | -import com.sun.mail.util.PropUtil; |
| 19 | +import jakarta.activation.DataHandler; |
| 20 | +import jakarta.activation.DataSource; |
| 21 | +import jakarta.activation.FileDataSource; |
| 22 | +import jakarta.mail.BodyPart; |
| 23 | +import jakarta.mail.EncodingAware; |
| 24 | +import jakarta.mail.FolderClosedException; |
| 25 | +import jakarta.mail.Header; |
| 26 | +import jakarta.mail.IllegalWriteException; |
| 27 | +import jakarta.mail.Message; |
| 28 | +import jakarta.mail.MessageContext; |
| 29 | +import jakarta.mail.MessageRemovedException; |
| 30 | +import jakarta.mail.MessagingException; |
| 31 | +import jakarta.mail.Multipart; |
| 32 | +import jakarta.mail.Part; |
| 33 | +import jakarta.mail.Session; |
| 34 | + |
| 35 | +import java.io.BufferedInputStream; |
| 36 | +import java.io.BufferedOutputStream; |
| 37 | +import java.io.ByteArrayInputStream; |
| 38 | +import java.io.File; |
| 39 | +import java.io.FileOutputStream; |
| 40 | +import java.io.IOException; |
| 41 | +import java.io.InputStream; |
| 42 | +import java.io.OutputStream; |
| 43 | +import java.io.UnsupportedEncodingException; |
| 44 | +import java.util.ArrayList; |
| 45 | +import java.util.Enumeration; |
| 46 | +import java.util.List; |
| 47 | +import java.util.Properties; |
| 48 | + |
24 | 49 | import com.sun.mail.util.ASCIIUtility; |
25 | | -import com.sun.mail.util.MimeUtil; |
26 | | -import com.sun.mail.util.MessageRemovedIOException; |
27 | 50 | import com.sun.mail.util.FolderClosedIOException; |
28 | 51 | import com.sun.mail.util.LineOutputStream; |
| 52 | +import com.sun.mail.util.MessageRemovedIOException; |
| 53 | +import com.sun.mail.util.MimeUtil; |
| 54 | +import com.sun.mail.util.PropUtil; |
29 | 55 |
|
30 | 56 | /** |
31 | 57 | * This class represents a MIME body part. It implements the |
@@ -193,6 +219,34 @@ public MimeBodyPart(InternetHeaders headers, byte[] content) |
193 | 219 | this.content = content; |
194 | 220 | } |
195 | 221 |
|
| 222 | + /** |
| 223 | + * Initializes MimeBodyPart from the InputStream is and it overwrites |
| 224 | + * properties from session. |
| 225 | + * |
| 226 | + * @param session Session object for this message |
| 227 | + * @param is the message input stream |
| 228 | + * @exception MessagingException for failures |
| 229 | + */ |
| 230 | + public MimeBodyPart(Session session, InputStream is) throws MessagingException { |
| 231 | + this(is); |
| 232 | + initializeProperties(session); |
| 233 | + } |
| 234 | + |
| 235 | + /** |
| 236 | + * Set the values from session properties if exist, otherwise it keeps the previous value. |
| 237 | + * @param session the not null session |
| 238 | + */ |
| 239 | + private void initializeProperties(Session session) { |
| 240 | + Properties props = session.getProperties(); |
| 241 | + setDefaultTextCharset = PropUtil.getBooleanProperty(props, "mail.mime.setdefaulttextcharset", setDefaultTextCharset); |
| 242 | + setContentTypeFileName = PropUtil.getBooleanProperty(props, "mail.mime.setcontenttypefilename", setContentTypeFileName); |
| 243 | + encodeFileName = PropUtil.getBooleanProperty(props, "mail.mime.encodefilename", encodeFileName); |
| 244 | + decodeFileName = PropUtil.getBooleanProperty(props, "mail.mime.decodefilename", decodeFileName); |
| 245 | + ignoreMultipartEncoding = PropUtil.getBooleanProperty(props, "mail.mime.ignoremultipartencoding", ignoreMultipartEncoding); |
| 246 | + allowutf8 = PropUtil.getBooleanProperty(props, "mail.mime.allowutf8", allowutf8); |
| 247 | + cacheMultipart = PropUtil.getBooleanProperty(props, "mail.mime.cachemultipart", cacheMultipart); |
| 248 | + } |
| 249 | + |
196 | 250 | /** |
197 | 251 | * Return the size of the content of this body part in bytes. |
198 | 252 | * Return -1 if the size cannot be determined. <p> |
|
0 commit comments