java


MimePartBody.getDisposition() returning null for inline parts


So I am trying to make a dragNdrop application which takes .eml files and saves the various bits.
The attachement part has not given me any issues but the message body and images contained are.
In my code I am using the javax.mail library.
Using the method
MimeBodyPart.getDisposition()
It correctly gives back 'attachment' when I print out the string but for the inline part it gives back 'null' and clumps together the images and body.
In the .eml file(generated with lotus notes) you can clearly see the Content-Disposition/ID/Type/Transfer-encoding... of each part.
Can anyone tell me what I am missing?
Here is the loop that deals with this:
for (File file: files) {
System.out.println(file.getPath());
Properties props = System.getProperties();
props.put("mail.host", "smtp.dummydomain.com");
props.put("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(props, null);
try {
InputStream source = new FileInputStream(file.getPath());
MimeMessage message = new MimeMessage(mailSession, source);
Multipart multiPart = (Multipart) message.getContent();
for (int i = 0; i < multiPart.getCount(); i++) {
MimeBodyPart part = (MimeBodyPart) multiPart.getBodyPart(i);
System.out.println(part.getDisposition());
if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
System.out.println("part " + i);
part.saveFile("C:/" + part.getFileName());
}
}
} catch (MessagingException | IOException e) {
e.printStackTrace();
}
}
The file object is correctly initialized since I get the pathname back and also the attachment saved.
Any help would be most appreciated.
The following is a slightly modified example of en .eml file. The inline image and the attachement where shortened to only a few lines to enable me to post it here:
From: someone#domain.com
X-Notes-Item: Mon, 8 May 2017 10:59:55 +0200;
type=400; name=OriginalModTime
X-Notes-Item: Memo;
name=Form
X-Notes-Item: stdNotesLtr25;
name=Logo
X-Notes-Item: ;
name=dLogo
X-Notes-Item: True;
name=useApplet
X-Notes-Item: 1;
name=DefaultMailSaveOptions
X-Notes-Item: 1;
name=ExpandPersonalGroups
X-Notes-Item: ;
name=tmpImp
X-Notes-Item: ;
name=Sign
X-Notes-Item: Stack Overflow saved my life.;
flags=6; name=$Abstract
X-Notes-Item: Vertraulich;
name=ConfidentialString
X-Notes-Item: ;
name=Classification
Subject: Example email
X-KeepSent: 2C23BC4F:883C3D54-C125811A:0030D552;
type=4; name=$KeepSent
To: NJun#domain.com
X-Notes-Item: ;
flags=45; name=InetCopyTo
X-Notes-Item: 1;
name=$StorageTo
X-Mailer: IBM Notes Release 9.0.1FP7 August 18, 2016
Message-ID: <OF2C23BC4F.883C3D54-ONC125811A.0030D552-C125811A.00316E89#LocalDomain>
Sender: NJun#domain.com
Date: Mon, 8 May 2017 10:59:55 +0200
X-Notes-Item: 0;
name=Encrypt
X-Notes-Item: CN=N Jun/OU=GU/OU=AT/O=domain;
type=501; flags=44; name=$UpdatedBy
X-Notes-Item: 2C23BC4F:883C3D54-C125811A:0030D552;
type=4; name=$Orig
X-Notes-Item: ;
type=501; name=Categories
X-Notes-Item: ;
type=401; name=$Revisions
X-Notes-Item: CN=S-NOTESGU001/OU=AT/O=domain;
type=501; flags=0; name=RouteServers
X-Notes-Item: 08-May-2017 10:59:55 CEDT/08-May-2017 10:59:55 CEDT;
type=401; flags=0; name=RouteTimes
X-Notes-Item: Mon, 8 May 2017 10:59:55 +0200;
type=400; name=DeliveredDate
X-Notes-Item: 2C23BC4F:883C3D54-C125811A:0030D552;
type=4; name=$TUA
X-Notes-Item: 1;
name=$NoteHasNativeMIME
X-Notes-Item: CN=N Jun/OU=GU/OU=AT/O=domain#domain;
name=OriginalTo
X-Notes-Item: CN=N Jun/OU=GU/OU=AT/O=domain;
name=OriginalFrom
X-Notes-Item: CN=someone/O=domain;
name=OriginalPrincipal
X-MIMETrack: Serialize by notes2.exe on N Jun/GU/AT/domain(Release 9.0.1FP7|August
18, 2016) at 08.05.2017 11:40:46
MIME-Version: 1.0
Content-type: multipart/mixed;
Boundary="0__=4EBB0B89DFA353C28f9e8a93df938690918c4EBB0B89DFA353C2"
--0__=4EBB0B89DFA353C28f9e8a93df938690918c4EBB0B89DFA353C2
Content-type: multipart/related;
Boundary="1__=4EBB0B89DFA353C28f9e8a93df938690918c4EBB0B89DFA353C2"
--1__=4EBB0B89DFA353C28f9e8a93df938690918c4EBB0B89DFA353C2
Content-type: text/html; charset=US-ASCII
Content-Disposition: inline
<html><body>
<table id="memoReadTable" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="top"><td width="0%"><img width="1" height="1" src="/icons/ecblank.gif" border="0" alt=""></td><td width="100%"><img width="1" height="1" src="/icons/ecblank.gif" border="0" alt=""><br>
</td><td width="1%"><img width="53" height="1" src="/icons/ecblank.gif" border="0" alt=""><br>
</td></tr>
<tr valign="top"><td width="1%"><img width="90" height="1" src="/icons/ecblank.gif" border="0" alt=""><br>
</td><td width="100%"><img width="1" height="1" src="/icons/ecblank.gif" border="0" alt=""><br>
</td><td width="1%"><img width="53" height="1" src="/icons/ecblank.gif" border="0" alt=""><br>
</td></tr>
<tr valign="top"><td width="1%"><img width="102" height="1" src="/icons/ecblank.gif" border="0" alt=""><br>
<ul style="padding-left: 4pt"><font size="1" color="#929292" face="sans-serif">An:</font></ul>
</td><td width="100%" valign="middle"><img width="1" height="1" src="/icons/ecblank.gif" border="0" alt=""><br>
<font size="1" face="sans-serif">NJun#domain.com</font></td><td width="1%"><img width="53" height="1" src="/icons/ecblank.gif" border="0" alt=""><br>
</td></tr>
</table>
<font size="2" face="sans-serif">Stack Overflow saved my life.</font><br>
<br>
<img src="cid:0__=4EBB0B89DFA353C28f9e8a93df93869091#local" width="1030" height="282"><br>
<i>(Siehe angehÃĪngte Datei: DT between trees.jpg)</i></body></html>
--1__=4EBB0B89DFA353C28f9e8a93df938690918c4EBB0B89DFA353C2
Content-type: image/gif;
name="02629422.gif"
Content-Disposition: inline; filename="02629422.gif"
Content-ID: <0__=4EBB0B89DFA353C28f9e8a93df93869091#local>
Content-transfer-encoding: base64
R0lGODlhBgQaAecAAP///xgQGCAYIPDw8Ojo6CggKDAoMPj48JCQkEA4QGBYYODg4NjY2PD4+Gho
aNDQ0CAQGKCgoBgQIMjIyDgwOMDAwKioqLi4uBgQKCAYKLCwsOjw+Pj46FBIUOj4+BgQMCgQGCgY
...........Shortened............
QAgMLxngkLgwYcIFO1OWQHbZObbs2bQpHligJsKPEhEuMJhaO7jw4cSLGz8+2EkYLTIC9QACaUoW
FRACGDFAgQ9S5Ny7e/8OPrz48eTLkz8wYADwh+nTrzcPP778+fTr27+PP7/+/fz7+/8PYIACDkhg
gQYeiGCCCi4SyGCDDj4IYYQSTkhhhRZeOFJAADs=
--1__=4EBB0B89DFA353C28f9e8a93df938690918c4EBB0B89DFA353C2--
--0__=4EBB0B89DFA353C28f9e8a93df938690918c4EBB0B89DFA353C2
Content-type: image/jpeg;
name="DT between trees.jpg"
Content-Disposition: attachment; filename="DT between trees.jpg"
Content-ID: <C3__=4EBB0B89DFA353C28f9e8a93df93869091#local>
Content-transfer-encoding: base64
/9j/4V/+RXhpZgAASUkqAAgAAAAMAA4BAgAgAAAA8BUAAA8BAgAYAAAAEBYAABABAgARAAAAKBYA
ABIBAwABAAAAAQAAABoBBQABAAAApBAAABsBBQABAAAArBAAACgBAwABAAAAAgAAADEBAgAgAAAA
.................Shortened...............................................
M0+RCg4q1qzknLUqyTbFOT0rK87zXOPWk11Mmf/V6rB29earngtnmvwGL1P02EtTOuJGY4FRAFQM
810dDrU1YXzATjNaFqFHJqXsS5XNaFl2jnipJmDIdtYqN2YSZ//W3pgd1Y13aPK5Jr8Op6I/SpS6
C29kUIxWtaQBW9TUVJ3MXM3rYKAPpUz4IxXI1qZt3ZCVXn1qtMUweBWdtTRH/9k=
--0__=4EBB0B89DFA353C28f9e8a93df938690918c4EBB0B89DFA353C2--
Your example .eml file shows a multipart/related nested inside the outer multipart/mixed. The msgshow.java sample program shows that the message has this structure:
This is the message envelope
---------------------------
FROM: someone#domain.com
REPLY TO: someone#domain.com
TO: NJun#domain.com
SUBJECT: Example email
SendDate: Mon May 08 01:59:55 PDT 2017
FLAGS:
X-Mailer: IBM Notes Release 9.0.1FP7 August 18, 2016
CONTENT-TYPE: multipart/mixed;
boundary="0__=4EBB0B89DFA353C28f9e8a93df938690918c4EBB0B89DFA353C2"
This is a Multipart
---------------------------
CONTENT-TYPE: multipart/related;
boundary="1__=4EBB0B89DFA353C28f9e8a93df938690918c4EBB0B89DFA353C2"
This is a Multipart
---------------------------
CONTENT-TYPE: text/html; charset=US-ASCII
---------------------------
CONTENT-TYPE: image/gif; name=02629422.gif
FILENAME: 02629422.gif
---------------------------
CONTENT-TYPE: image/jpeg; name="DT between trees.jpg"
FILENAME: DT between trees.jpg
---------------------------
Your sample code is only processing the outer multipart/mixed. The outer multipart/mixed also includes an image/jpeg attachment, which your code should find. The inner multipart/related includes an image/gif inline component, which your code will never see.
I can't see any reason your code should get null for the disposition of the image/jpeg part. Are you using IMAP to access the message? What does the JavaMail debug output show?

Related Links

I want to start thread from my service, so that the operations do not run in the main thread of android
Error in Ant file
how to get values for customfields of a custom record in Netsuite
invalid_client in jsonresponse in oauth2 android
MVC problems. Getting values in Controller from View
Good way to write combination of conditions
How to make dex2jar to skip certain classes while converting dex to jar?
Run main method from GUI button in netbeans
Hibernating - Generating part of a composite key
Bad operand types for binary operator. Why doesn't this work?
Getting UnmarshallingFailureException Expected elements are (none) at
Converting a pointer to an array in C++ to Java (OpenCV)
Solr on Drupal HTTP ERROR 500
Android edittext and virtual keyboard
How to resume app by notification
Visual Custom Grid

Categories

HOME
java
cloud
reflection
gremlin
mfc
nullpointerexception
fft
lodash
read-eval-print-loop
routes
webpack-2
echarts
google-apps-marketplace
lombok
opentracing
django-admin
saxon
database-replication
django-cms
visual-composer
scichart
emulator
reverse-proxy
scriptcs
arabic
css-animations
tapestry
bootstrap-tour
url-scheme
phpfox
webkitspeechrecognition
lightswitch-2013
javascriptcore
yadcf
winrt-xaml-toolkit
typed.js
openoffice.org
retina-display
swift3.0.2
splice
hp-ux
reactive-cocoa-5
qcombobox
btrace
osx-mavericks
komodoedit
worksheet
lift-json
mcafee
titanium-android
intrusion-detection
py2app
django-debug-toolbar
gridview-sorting
ubuntu-10.04
goose
wso2cloud
execute
python-3.2
android-listview
0xdbe
ibaction
website-monitoring
c3
asp.net-dynamic-data
id3v2
zend-route
mesa
article
fluentautomation
valueconverter
meteor-velocity
java.nio.file
typo3-neos
viadeo
gwt-rpc
back-stack
yui-compressor
comaddin
http-unit
referrer
dbproviderfactories
ohm
assembly-loading
data-loss
zpt
android-sdk-2.1
sql-server-profiler
cxxtest
suppress
forums
thunderbird-lightning
ctp4
xetex
commodore
ajax-forms

Resources

Encrypt Message