@Nullable private String extractProtectedSubject(MessageViewInfo messageViewInfo) { String protectedHeadersParam = MimeUtility.getHeaderParameter( messageViewInfo.rootPart.getContentType(), "protected-headers"); String[] protectedSubjectHeader = messageViewInfo.rootPart.getHeader("Subject"); boolean hasProtectedSubject = "v1".equalsIgnoreCase(protectedHeadersParam) && protectedSubjectHeader.length > 0; if (hasProtectedSubject) { return protectedSubjectHeader[0]; } return null; }
public static boolean isMultipartSignedOpenPgpProtocol(Part part) { if (!isSameMimeType(part.getMimeType(), MULTIPART_SIGNED)) { throw new IllegalArgumentException("Part is not multipart/signed!"); } String protocolParameter = MimeUtility.getHeaderParameter(part.getContentType(), PROTOCOL_PARAMETER); return APPLICATION_PGP_SIGNATURE.equalsIgnoreCase(protocolParameter); }
public static boolean isMultipartEncryptedOpenPgpProtocol(Part part) { if (!isSameMimeType(part.getMimeType(), MULTIPART_ENCRYPTED)) { throw new IllegalArgumentException("Part is not multipart/encrypted!"); } String protocolParameter = MimeUtility.getHeaderParameter(part.getContentType(), PROTOCOL_PARAMETER); return APPLICATION_PGP_ENCRYPTED.equalsIgnoreCase(protocolParameter); }
String charset = getHeaderParameter(part.getContentType(), "charset");
@WorkerThread private AttachmentViewInfo extractAttachmentInfo(Part part, Uri uri, long size, boolean isContentAvailable) { boolean inlineAttachment = false; String mimeType = part.getMimeType(); String contentTypeHeader = part.getContentType(); String contentDisposition = part.getDisposition(); String name = MimeUtility.getHeaderParameter(contentDisposition, "filename"); if (name == null) { name = MimeUtility.getHeaderParameter(contentTypeHeader, "name"); } if (name == null) { String extension = null; if (mimeType != null) { extension = MimeUtility.getExtensionByMimeType(mimeType); } name = "noname" + ((extension != null) ? "." + extension : ""); } // Inline parts with a Content-Id header and a MIME type of image/* are probably components of an HTML message, // not attachments. if (contentDisposition != null && MimeUtility.getHeaderParameter(contentDisposition, null).matches("^(?i:inline)") && part.getHeader(MimeHeader.HEADER_CONTENT_ID).length > 0 && mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("image/")) { inlineAttachment = true; } long attachmentSize = extractAttachmentSize(contentDisposition, size); return new AttachmentViewInfo(mimeType, name, attachmentSize, uri, inlineAttachment, part, isContentAvailable); }
Viewable viewable; if (isSameMimeType(mimeType, "text/plain")) { if (isFormatFlowed(part.getContentType())) { boolean delSp = FlowedMessageUtils.isDelSp(part.getContentType()); viewable = new Flowed(part, delSp); } else {
public static boolean isPartMultipartEncrypted(Part part) { if (!isSameMimeType(part.getMimeType(), MULTIPART_ENCRYPTED)) { return false; } if (! (part.getBody() instanceof MimeMultipart)) { return false; } MimeMultipart mimeMultipart = (MimeMultipart) part.getBody(); if (mimeMultipart.getCount() != 2) { return false; } String protocolParameter = MimeUtility.getHeaderParameter(part.getContentType(), PROTOCOL_PARAMETER); // for partially downloaded messages the protocol parameter isn't yet available, so we'll just assume it's ok boolean dataUnavailable = protocolParameter == null && mimeMultipart.getBodyPart(1).getBody() == null; boolean protocolMatches = isSameMimeType(protocolParameter, mimeMultipart.getBodyPart(0).getMimeType()); return dataUnavailable || protocolMatches; }
private static boolean isPartMultipartSigned(Part part) { if (!isSameMimeType(part.getMimeType(), MULTIPART_SIGNED)) { return false; } if (! (part.getBody() instanceof MimeMultipart)) { return false; } MimeMultipart mimeMultipart = (MimeMultipart) part.getBody(); if (mimeMultipart.getCount() != 2) { return false; } String protocolParameter = MimeUtility.getHeaderParameter(part.getContentType(), PROTOCOL_PARAMETER); // for partially downloaded messages the protocol parameter isn't yet available, so we'll just assume it's ok boolean dataUnavailable = protocolParameter == null && mimeMultipart.getBodyPart(0).getBody() == null; boolean protocolMatches = isSameMimeType(protocolParameter, mimeMultipart.getBodyPart(1).getMimeType()); return dataUnavailable || protocolMatches; }
public static void setBody(Part part, Body body) throws MessagingException { part.setBody(body); if (part instanceof Message) { part.setHeader("MIME-Version", "1.0"); } if (body instanceof Multipart) { Multipart multipart = ((Multipart) body); multipart.setParent(part); String contentType = Headers.contentTypeForMultipart(multipart.getMimeType(), multipart.getBoundary()); part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType); // note: if this is ever changed to 8bit, multipart/signed parts must always be 7bit! setEncoding(part, MimeUtil.ENC_7BIT); } else if (body instanceof TextBody) { MimeValue contentTypeHeader = MimeParameterDecoder.decode(part.getContentType()); String mimeType = contentTypeHeader.getValue(); if (MimeUtility.mimeTypeMatches(mimeType, "text/*")) { String name = contentTypeHeader.getParameters().get("name"); String contentType = Headers.contentType(mimeType, "utf-8", name); part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType); } else { part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, mimeType); } setEncoding(part, MimeUtil.ENC_QUOTED_PRINTABLE); } else if (body instanceof RawDataBody) { String encoding = ((RawDataBody) body).getEncoding(); part.setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, encoding); } }