44import org .jetbrains .annotations .NotNull ;
55import org .jetbrains .annotations .Nullable ;
66import org .simplejavamail .internal .util .MiscUtil ;
7+ import org .simplejavamail .internal .util .NaturalEntryKeyComparator ;
78import org .simplejavamail .internal .util .Preconditions ;
89
910import javax .activation .ActivationDataFlavor ;
2930import java .io .IOException ;
3031import java .io .InputStream ;
3132import java .io .UnsupportedEncodingException ;
33+ import java .util .AbstractMap .SimpleEntry ;
3234import java .util .ArrayList ;
3335import java .util .Arrays ;
3436import java .util .Collection ;
3840import java .util .Iterator ;
3941import java .util .List ;
4042import java .util .Map ;
43+ import java .util .Set ;
4144import java .util .TreeMap ;
45+ import java .util .TreeSet ;
4246import java .util .regex .Matcher ;
4347import java .util .regex .Pattern ;
4448
@@ -160,13 +164,13 @@ private static void parseMimePartTree(@NotNull final MimePart currentPart, @NotN
160164 final DataSource ds = createDataSource (currentPart , fetchAttachmentData );
161165 // if the diposition is not provided, for now the part should be treated as inline (later non-embedded inline attachments are moved)
162166 if (Part .ATTACHMENT .equalsIgnoreCase (disposition )) {
163- parsedComponents .attachmentList .put ( parseResourceNameOrUnnamed (parseContentID (currentPart ), parseFileName (currentPart )), ds );
167+ parsedComponents .attachmentList .add ( new SimpleEntry <>( parseResourceNameOrUnnamed (parseContentID (currentPart ), parseFileName (currentPart )), ds ) );
164168 } else if (disposition == null || Part .INLINE .equalsIgnoreCase (disposition )) {
165169 if (parseContentID (currentPart ) != null ) {
166170 parsedComponents .cidMap .put (parseContentID (currentPart ), ds );
167171 } else {
168172 // contentID missing -> treat as standard attachment
169- parsedComponents .attachmentList .put ( parseResourceNameOrUnnamed (null , parseFileName (currentPart )), ds );
173+ parsedComponents .attachmentList .add ( new SimpleEntry <>( parseResourceNameOrUnnamed (null , parseFileName (currentPart )), ds ) );
170174 }
171175 } else {
172176 throw new IllegalStateException ("invalid attachment type" );
@@ -549,14 +553,15 @@ static void moveInvalidEmbeddedResourcesToAttachments(ParsedMimeMessageComponent
549553 Map .Entry <String , DataSource > cidEntry = it .next ();
550554 String cid = extractCID (cidEntry .getKey ());
551555 if (!htmlContent .contains ("cid:" + cid )) {
552- parsedComponents .attachmentList .put ( cid , cidEntry .getValue ());
556+ parsedComponents .attachmentList .add ( new SimpleEntry <>( cid , cidEntry .getValue () ));
553557 it .remove ();
554558 }
555559 }
556560 }
557561
558562 public static class ParsedMimeMessageComponents {
559- final Map <String , DataSource > attachmentList = new TreeMap <>();
563+ @ SuppressWarnings ("unchecked" )
564+ final Set <Map .Entry <String , DataSource >> attachmentList = new TreeSet <>(NaturalEntryKeyComparator .INSTANCE );
560565 final Map <String , DataSource > cidMap = new TreeMap <>();
561566 private final Map <String , Collection <Object >> headers = new HashMap <>();
562567 private final List <InternetAddress > toAddresses = new ArrayList <>();
@@ -580,7 +585,7 @@ public String getMessageId() {
580585 return messageId ;
581586 }
582587
583- public Map <String , DataSource > getAttachmentList () {
588+ public Set < Map . Entry <String , DataSource > > getAttachmentList () {
584589 return attachmentList ;
585590 }
586591
0 commit comments