1 /* |
1 /* |
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
81 protected static final int FI_ENCODED_FLAG = 16; // 10000 |
81 protected static final int FI_ENCODED_FLAG = 16; // 10000 |
82 |
82 |
83 protected MimeHeaders headers; |
83 protected MimeHeaders headers; |
84 protected ContentType contentType; |
84 protected ContentType contentType; |
85 protected SOAPPartImpl soapPartImpl; |
85 protected SOAPPartImpl soapPartImpl; |
86 protected FinalArrayList attachments; |
86 protected FinalArrayList<AttachmentPart> attachments; |
87 protected boolean saved = false; |
87 protected boolean saved = false; |
88 protected byte[] messageBytes; |
88 protected byte[] messageBytes; |
89 protected int messageByteCount; |
89 protected int messageByteCount; |
90 protected HashMap properties = new HashMap(); |
90 protected HashMap properties = new HashMap(); |
91 |
91 |
853 this.optimizeAttachmentProcessing = true; |
853 this.optimizeAttachmentProcessing = true; |
854 } catch (Exception e) { |
854 } catch (Exception e) { |
855 throw new RuntimeException(e); |
855 throw new RuntimeException(e); |
856 } |
856 } |
857 if (attachments == null) |
857 if (attachments == null) |
858 attachments = new FinalArrayList(); |
858 attachments = new FinalArrayList<AttachmentPart>(); |
859 |
859 |
860 attachments.add(attachment); |
860 attachments.add(attachment); |
861 |
861 |
862 needsSave(); |
862 needsSave(); |
863 } |
863 } |
885 ct.setSubType(split[1]); |
885 ct.setSubType(split[1]); |
886 ct.setParameter("charset", charset); |
886 ct.setParameter("charset", charset); |
887 headers.setHeader("Content-Type", ct.toString()); |
887 headers.setHeader("Content-Type", ct.toString()); |
888 } |
888 } |
889 |
889 |
890 private class MimeMatchingIterator implements Iterator { |
890 private class MimeMatchingIterator implements Iterator<AttachmentPart> { |
891 public MimeMatchingIterator(MimeHeaders headers) { |
891 public MimeMatchingIterator(MimeHeaders headers) { |
892 this.headers = headers; |
892 this.headers = headers; |
893 this.iter = attachments.iterator(); |
893 this.iter = attachments.iterator(); |
894 } |
894 } |
895 |
895 |
896 private Iterator iter; |
896 private Iterator<AttachmentPart> iter; |
897 private MimeHeaders headers; |
897 private MimeHeaders headers; |
898 private Object nextAttachment; |
898 private AttachmentPart nextAttachment; |
899 |
899 |
900 public boolean hasNext() { |
900 public boolean hasNext() { |
901 if (nextAttachment == null) |
901 if (nextAttachment == null) |
902 nextAttachment = nextMatch(); |
902 nextAttachment = nextMatch(); |
903 return nextAttachment != null; |
903 return nextAttachment != null; |
904 } |
904 } |
905 |
905 |
906 public Object next() { |
906 public AttachmentPart next() { |
907 if (nextAttachment != null) { |
907 if (nextAttachment != null) { |
908 Object ret = nextAttachment; |
908 AttachmentPart ret = nextAttachment; |
909 nextAttachment = null; |
909 nextAttachment = null; |
910 return ret; |
910 return ret; |
911 } |
911 } |
912 |
912 |
913 if (hasNext()) |
913 if (hasNext()) |
914 return nextAttachment; |
914 return nextAttachment; |
915 |
915 |
916 return null; |
916 return null; |
917 } |
917 } |
918 |
918 |
919 Object nextMatch() { |
919 AttachmentPart nextMatch() { |
920 while (iter.hasNext()) { |
920 while (iter.hasNext()) { |
921 AttachmentPartImpl ap = (AttachmentPartImpl) iter.next(); |
921 AttachmentPartImpl ap = (AttachmentPartImpl) iter.next(); |
922 if (ap.hasAllHeaders(headers)) |
922 if (ap.hasAllHeaders(headers)) |
923 return ap; |
923 return ap; |
924 } |
924 } |
949 throw new RuntimeException(e); |
949 throw new RuntimeException(e); |
950 } |
950 } |
951 if (attachments == null) |
951 if (attachments == null) |
952 return ; |
952 return ; |
953 |
953 |
954 Iterator it = new MimeMatchingIterator(headers); |
954 Iterator<AttachmentPart> it = new MimeMatchingIterator(headers); |
955 while (it.hasNext()) { |
955 while (it.hasNext()) { |
956 int index = attachments.indexOf(it.next()); |
956 int index = attachments.indexOf(it.next()); |
957 attachments.set(index, null); |
957 attachments.set(index, null); |
958 } |
958 } |
959 FinalArrayList f = new FinalArrayList(); |
959 FinalArrayList<AttachmentPart> f = new FinalArrayList<AttachmentPart>(); |
960 for (int i = 0; i < attachments.size(); i++) { |
960 for (int i = 0; i < attachments.size(); i++) { |
961 if (attachments.get(i) != null) { |
961 if (attachments.get(i) != null) { |
962 f.add(attachments.get(i)); |
962 f.add(attachments.get(i)); |
963 } |
963 } |
964 } |
964 } |
1064 SOAPPartImpl sp = (SOAPPartImpl) getSOAPPart(); |
1064 SOAPPartImpl sp = (SOAPPartImpl) getSOAPPart(); |
1065 return sp.getContentAsStream(); |
1065 return sp.getContentAsStream(); |
1066 } |
1066 } |
1067 |
1067 |
1068 private String convertToSingleLine(String contentType) { |
1068 private String convertToSingleLine(String contentType) { |
1069 StringBuffer buffer = new StringBuffer(); |
1069 StringBuilder buffer = new StringBuilder(); |
1070 for (int i = 0; i < contentType.length(); i ++) { |
1070 for (int i = 0; i < contentType.length(); i ++) { |
1071 char c = contentType.charAt(i); |
1071 char c = contentType.charAt(i); |
1072 if (c != '\r' && c != '\n' && c != '\t') |
1072 if (c != '\r' && c != '\n' && c != '\t') |
1073 buffer.append(c); |
1073 buffer.append(c); |
1074 } |
1074 } |
1096 if (!switchOffBM && !switchOffLazyAttachment && |
1096 if (!switchOffBM && !switchOffLazyAttachment && |
1097 (multiPart != null) && !attachmentsInitialized) { |
1097 (multiPart != null) && !attachmentsInitialized) { |
1098 headerAndBody = new BMMimeMultipart(); |
1098 headerAndBody = new BMMimeMultipart(); |
1099 headerAndBody.addBodyPart(mimeSoapPart); |
1099 headerAndBody.addBodyPart(mimeSoapPart); |
1100 if (attachments != null) { |
1100 if (attachments != null) { |
1101 for (Iterator eachAttachment = attachments.iterator(); |
1101 for (Iterator<AttachmentPart> eachAttachment = attachments.iterator(); |
1102 eachAttachment.hasNext();) { |
1102 eachAttachment.hasNext();) { |
1103 headerAndBody.addBodyPart( |
1103 headerAndBody.addBodyPart( |
1104 ((AttachmentPartImpl) eachAttachment.next()) |
1104 ((AttachmentPartImpl) eachAttachment.next()) |
1105 .getMimePart()); |
1105 .getMimePart()); |
1106 } |
1106 } |
1422 if (attachmentsInitialized || (multiPart == null)) { |
1422 if (attachmentsInitialized || (multiPart == null)) { |
1423 return; |
1423 return; |
1424 } |
1424 } |
1425 |
1425 |
1426 if (attachments == null) |
1426 if (attachments == null) |
1427 attachments = new FinalArrayList(); |
1427 attachments = new FinalArrayList<AttachmentPart>(); |
1428 |
1428 |
1429 int count = multiPart.getCount(); |
1429 int count = multiPart.getCount(); |
1430 for (int i=0; i < count; i++ ) { |
1430 for (int i=0; i < count; i++ ) { |
1431 initializeAttachment(multiPart.getBodyPart(i)); |
1431 initializeAttachment(multiPart.getBodyPart(i)); |
1432 } |
1432 } |