本文整理汇总了Java中org.apache.james.mime4j.util.MimeUtil类的典型用法代码示例。如果您正苦于以下问题:Java MimeUtil类的具体用法?Java MimeUtil怎么用?Java MimeUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MimeUtil类属于org.apache.james.mime4j.util包,在下文中一共展示了MimeUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mimeBuildSignedMessage
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
private void mimeBuildSignedMessage(@NonNull BodyPart signedBodyPart, Intent result) throws MessagingException {
if (!cryptoStatus.isSigningEnabled()) {
throw new IllegalStateException("call to mimeBuildSignedMessage while signing isn't enabled!");
}
byte[] signedData = result.getByteArrayExtra(OpenPgpApi.RESULT_DETACHED_SIGNATURE);
if (signedData == null) {
throw new MessagingException("didn't find expected RESULT_DETACHED_SIGNATURE in api call result");
}
MimeMultipart multipartSigned = createMimeMultipart();
multipartSigned.setSubType("signed");
multipartSigned.addBodyPart(signedBodyPart);
multipartSigned.addBodyPart(
new MimeBodyPart(new BinaryMemoryBody(signedData, MimeUtil.ENC_7BIT),
"application/pgp-signature; name=\"signature.asc\""));
MimeMessageHelper.setBody(currentProcessedMimeMessage, multipartSigned);
String contentType = String.format(
"multipart/signed; boundary=\"%s\";\r\n protocol=\"application/pgp-signature\"",
multipartSigned.getBoundary());
if (result.hasExtra(OpenPgpApi.RESULT_SIGNATURE_MICALG)) {
String micAlgParameter = result.getStringExtra(OpenPgpApi.RESULT_SIGNATURE_MICALG);
contentType += String.format("; micalg=\"%s\"", micAlgParameter);
} else {
Timber.e("missing micalg parameter for pgp multipart/signed!");
}
currentProcessedMimeMessage.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType);
}
示例2: getDecodingInputStream
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
InputStream getDecodingInputStream(final InputStream rawInputStream, @Nullable String encoding) {
if (MimeUtil.ENC_BASE64.equals(encoding)) {
return new Base64InputStream(rawInputStream) {
@Override
public void close() throws IOException {
super.close();
rawInputStream.close();
}
};
}
if (MimeUtil.ENC_QUOTED_PRINTABLE.equals(encoding)) {
return new QuotedPrintableInputStream(rawInputStream) {
@Override
public void close() throws IOException {
super.close();
rawInputStream.close();
}
};
}
return rawInputStream;
}
示例3: getSize
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
@Override
public long getSize() {
try {
byte[] bytes = text.getBytes(charset);
if (MimeUtil.ENC_QUOTED_PRINTABLE.equalsIgnoreCase(encoding)) {
return getLengthWhenQuotedPrintableEncoded(bytes);
} else if (MimeUtil.ENC_8BIT.equalsIgnoreCase(encoding)) {
return bytes.length;
} else {
throw new IllegalStateException("Cannot get size for encoding!");
}
} catch (IOException e) {
throw new RuntimeException("Couldn't get body size", e);
}
}
示例4: nestedMessage
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
private MimeMessage nestedMessage(MimeMessage subMessage)
throws MessagingException, IOException {
BinaryTempFileMessageBody tempMessageBody = new BinaryTempFileMessageBody(MimeUtil.ENC_8BIT);
OutputStream out = tempMessageBody.getOutputStream();
try {
subMessage.writeTo(out);
} finally {
out.close();
}
MimeBodyPart bodyPart = new MimeBodyPart(tempMessageBody, "message/rfc822");
bodyPart.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment");
bodyPart.setEncoding(MimeUtil.ENC_7BIT);
MimeMessage parentMessage = sampleMessage();
((Multipart) parentMessage.getBody()).addBodyPart(bodyPart);
return parentMessage;
}
示例5: binaryBodyPart
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
private MimeBodyPart binaryBodyPart() throws IOException,
MessagingException {
String encodedTestString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz0123456789+/\r\n";
BinaryTempFileBody tempFileBody = new BinaryTempFileBody(MimeUtil.ENC_BASE64);
InputStream in = new ByteArrayInputStream(
encodedTestString.getBytes("UTF-8"));
OutputStream out = tempFileBody.getOutputStream();
try {
IOUtils.copy(in, out);
} finally {
out.close();
}
MimeBodyPart bodyPart = new MimeBodyPart(tempFileBody,
"application/octet-stream");
bodyPart.setEncoding(MimeUtil.ENC_BASE64);
return bodyPart;
}
示例6: createBody
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
public static Body createBody(InputStream in, String contentTransferEncoding, String contentType)
throws IOException {
if (contentTransferEncoding != null) {
contentTransferEncoding = MimeUtility.getHeaderParameter(contentTransferEncoding, null);
}
BinaryTempFileBody tempBody;
if (MimeUtil.isMessage(contentType)) {
tempBody = new BinaryTempFileMessageBody(contentTransferEncoding);
} else {
tempBody = new BinaryTempFileBody(contentTransferEncoding);
}
OutputStream out = tempBody.getOutputStream();
try {
IOUtils.copy(in, out);
} finally {
out.close();
}
return tempBody;
}
示例7: setBody
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
@Override
public void setBody(Body body) throws MessagingException {
this.mBody = body;
setHeader("MIME-Version", "1.0");
if (body instanceof Multipart) {
Multipart multipart = ((Multipart)body);
multipart.setParent(this);
String type = multipart.getContentType();
setHeader(MimeHeader.HEADER_CONTENT_TYPE, type);
if ("multipart/signed".equalsIgnoreCase(type)) {
setEncoding(MimeUtil.ENC_7BIT);
} else {
setEncoding(MimeUtil.ENC_8BIT);
}
} else if (body instanceof TextBody) {
setHeader(MimeHeader.HEADER_CONTENT_TYPE, String.format("%s;\r\n charset=utf-8",
getMimeType()));
setEncoding(MimeUtil.ENC_8BIT);
}
}
示例8: writeTo
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
@Override
public void writeTo(OutputStream out) throws IOException, MessagingException {
InputStream in = getInputStream();
try {
if (MimeUtil.ENC_7BIT.equalsIgnoreCase(mEncoding)) {
/*
* If we knew the message was already 7bit clean, then it
* could be sent along without processing. But since we
* don't know, we recursively parse it.
*/
MimeMessage message = new MimeMessage(in, true);
message.setUsing7bitTransport();
message.writeTo(out);
} else {
IOUtils.copy(in, out);
}
} finally {
in.close();
}
}
示例9: setBody
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
public void setBody(Body body) throws MessagingException {
this.mBody = body;
if (body instanceof Multipart) {
Multipart multipart = ((Multipart)body);
multipart.setParent(this);
String type = multipart.getContentType();
setHeader(MimeHeader.HEADER_CONTENT_TYPE, type);
if ("multipart/signed".equalsIgnoreCase(type)) {
setEncoding(MimeUtil.ENC_7BIT);
} else {
setEncoding(MimeUtil.ENC_8BIT);
}
} else if (body instanceof TextBody) {
String contentType = String.format("%s;\r\n charset=utf-8", getMimeType());
String name = MimeUtility.getHeaderParameter(getContentType(), "name");
if (name != null) {
contentType += String.format(";\r\n name=\"%s\"", name);
}
setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType);
setEncoding(MimeUtil.ENC_8BIT);
}
}
示例10: writeTo
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
public static void writeTo(BinaryAttachmentBody body, OutputStream out) throws IOException,
MessagingException {
InputStream in = body.getInputStream();
try {
if (MimeUtil.ENC_7BIT.equalsIgnoreCase(body.getEncoding())) {
/*
* If we knew the message was already 7bit clean, then it
* could be sent along without processing. But since we
* don't know, we recursively parse it.
*/
MimeMessage message = new MimeMessage(in, true);
message.setUsing7bitTransport();
message.writeTo(out);
} else {
IOUtils.copy(in, out);
}
} finally {
in.close();
}
}
示例11: nestedMessage
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
private MimeMessage nestedMessage(MimeMessage subMessage)
throws MessagingException, IOException {
BinaryTempFileMessageBody tempMessageBody = new BinaryTempFileMessageBody();
tempMessageBody.setEncoding(MimeUtil.ENC_8BIT);
OutputStream out = tempMessageBody.getOutputStream();
try {
subMessage.writeTo(out);
} finally {
out.close();
}
MimeBodyPart bodyPart = new MimeBodyPart(tempMessageBody, "message/rfc822");
bodyPart.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment");
bodyPart.setEncoding(MimeUtil.ENC_8BIT);
MimeMessage parentMessage = sampleMessage();
((Multipart) parentMessage.getBody()).addBodyPart(bodyPart);
return parentMessage;
}
示例12: sampleMessage
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
private MimeMessage sampleMessage() throws MessagingException, IOException {
MimeMessage message = new MimeMessage();
message.setFrom(new Address("[email protected]"));
message.setRecipient(RecipientType.TO, new Address("[email protected]"));
message.setSubject("Test Message");
message.setHeader("Date", "Wed, 28 Aug 2013 08:51:09 -0400");
message.setEncoding(MimeUtil.ENC_8BIT);
NonRandomMimeMultipartTest multipartBody = new NonRandomMimeMultipartTest();
multipartBody.setSubType("mixed");
multipartBody.addBodyPart(textBodyPart(MimeUtil.ENC_8BIT));
multipartBody.addBodyPart(textBodyPart(MimeUtil.ENC_QUOTED_PRINTABLE));
multipartBody.addBodyPart(binaryBodyPart());
message.setBody(multipartBody);
return message;
}
示例13: binaryBodyPart
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
private MimeBodyPart binaryBodyPart() throws IOException,
MessagingException {
String encodedTestString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz0123456789+/";
BinaryTempFileBody tempFileBody = new BinaryTempFileBody();
InputStream in = new Base64InputStream(new ByteArrayInputStream(
encodedTestString.getBytes("UTF-8")));
OutputStream out = tempFileBody.getOutputStream();
try {
IOUtils.copy(in, out);
} finally {
out.close();
}
MimeBodyPart bodyPart = new MimeBodyPart(tempFileBody,
"application/octet-stream");
bodyPart.setEncoding(MimeUtil.ENC_BASE64);
return bodyPart;
}
示例14: writeTo
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
/**
* Write the content to the given outputstream
*
* @param out the outputstream to write to
* @param mode compatibility mode:
* {@link MessageUtils#LENIENT}, {@link MessageUtils#STRICT_ERROR}, {@link MessageUtils#STRICT_IGNORE}
* @throws IOException
*/
public void writeTo(OutputStream out, int mode) throws IOException, MimeException {
getHeader().writeTo(out, mode);
out.flush();
final Body body = getBody();
OutputStream encOut;
if (MimeUtil.ENC_BASE64.equals(getContentTransferEncoding())) {
encOut = CodecUtil.wrapBase64(out);
} else if (MimeUtil.ENC_QUOTED_PRINTABLE.equals(getContentTransferEncoding())) {
encOut = CodecUtil.wrapQuotedPrintable(out, (body instanceof BinaryBody));
} else {
encOut = out;
}
body.writeTo(encOut, mode);
encOut.flush();
// the Base64 output streams requires closing of the stream but
// we don't want it to close the inner stream so we override the behaviour
// for the wrapping stream writer.
if (encOut != out) encOut.close();
}
示例15: addField
import org.apache.james.mime4j.util.MimeUtil; //导入依赖的package包/类
public void addField(String name, String value) {
name = name.trim().toLowerCase();
if (MimeUtil.MIME_HEADER_MIME_VERSION.equals(name) && !isMimeVersionSet) {
parseMimeVersion(value);
} else if (MimeUtil.MIME_HEADER_CONTENT_ID.equals(name) && !isContentIdSet) {
parseContentId(value);
} else if (MimeUtil.MIME_HEADER_CONTENT_DESCRIPTION.equals(name) && !isContentDescriptionSet) {
parseContentDescription(value);
} else if (MimeUtil.MIME_HEADER_CONTENT_DISPOSITION.equals(name) && !isContentDispositionSet) {
parseContentDisposition(value);
} else if (MimeUtil.MIME_HEADER_LANGAUGE.equals(name) && !isContentLanguageSet) {
parseLanguage(value);
} else if (MimeUtil.MIME_HEADER_LOCATION.equals(name) && !isContentLocationSet) {
parseLocation(value);
} else if (MimeUtil.MIME_HEADER_MD5.equals(name) && !isContentMD5Set) {
parseMD5(value);
} else {
super.addField(name, value);
}
}