本文整理了Java中javax.mail.internet.MimeBodyPart.addHeader()
方法的一些代码示例,展示了MimeBodyPart.addHeader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeBodyPart.addHeader()
方法的具体详情如下:
包路径:javax.mail.internet.MimeBodyPart
类名称:MimeBodyPart
方法名:addHeader
[英]Add this value to the existing values for this header_name. Note that RFC 822 headers must contain only US-ASCII characters, so a header that contains non US-ASCII characters must be encoded as per the rules of RFC 2047.
[中]将此值添加到此标题名称的现有值中。请注意,RFC 822标头必须仅包含US-ASCII字符,因此包含非US-ASCII字符的标头必须按照RFC 2047的规则进行编码。
代码示例来源:origin: voldemort/voldemort
try {
keyBody.addHeader(CONTENT_TYPE, "application/octet-stream");
keyBody.addHeader(CONTENT_TRANSFER_ENCODING, "binary");
keyBody.addHeader(CONTENT_LOCATION, contentLocationKey);
} catch(MessagingException me) {
logger.error("Exception while constructing key body headers", me);
try {
valueBody.addHeader(CONTENT_TYPE, "application/octet-stream");
valueBody.addHeader(CONTENT_TRANSFER_ENCODING, "binary");
valueBody.addHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK, eTag);
valueBody.setContent(responseValue, "application/octet-stream");
valueBody.addHeader(RestMessageHeaders.CONTENT_LENGTH,
Integer.toString(responseValue.length));
代码示例来源:origin: voldemort/voldemort
try {
body.addHeader(CONTENT_TYPE, "application/octet-stream");
body.addHeader(CONTENT_TRANSFER_ENCODING, "binary");
body.addHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK, eTag);
body.setContent(responseValue, "application/octet-stream");
body.addHeader(RestMessageHeaders.CONTENT_LENGTH,
Integer.toString(responseValue.length));
代码示例来源:origin: pentaho/pentaho-kettle
private void addAttachedFilePart( FileObject file ) throws Exception {
// create a data source
MimeBodyPart files = new MimeBodyPart();
// create a data source
URLDataSource fds = new URLDataSource( file.getURL() );
// get a data Handler to manipulate this file type;
files.setDataHandler( new DataHandler( fds ) );
// include the file in the data source
files.setFileName( file.getName().getBaseName() );
// insist on base64 to preserve line endings
files.addHeader( "Content-Transfer-Encoding", "base64" );
// add the part with the file in the BodyPart();
data.parts.addBodyPart( files );
if ( isDetailed() ) {
logDetailed( BaseMessages.getString( PKG, "Mail.Log.AttachedFile", fds.getName() ) );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
files.addHeader( "Content-Transfer-Encoding", "base64" );
代码示例来源:origin: org.alfresco/alfresco-repository
private MimeBodyPart getTextBodyPart(String bodyText, String subtype, String mimeType) throws MessagingException
{
MimeBodyPart result = new MimeBodyPart();
result.setText(bodyText, AlfrescoImapConst.UTF_8, subtype);
result.addHeader(AlfrescoImapConst.CONTENT_TYPE, mimeType + AlfrescoImapConst.CHARSET_UTF8);
result.addHeader(AlfrescoImapConst.CONTENT_TRANSFER_ENCODING, AlfrescoImapConst.BASE_64_ENCODING);
return result;
}
代码示例来源:origin: Alfresco/alfresco-repository
private MimeBodyPart getTextBodyPart(String bodyText, String subtype, String mimeType) throws MessagingException
{
MimeBodyPart result = new MimeBodyPart();
result.setText(bodyText, AlfrescoImapConst.UTF_8, subtype);
result.addHeader(AlfrescoImapConst.CONTENT_TYPE, mimeType + AlfrescoImapConst.CHARSET_UTF8);
result.addHeader(AlfrescoImapConst.CONTENT_TRANSFER_ENCODING, AlfrescoImapConst.BASE_64_ENCODING);
return result;
}
代码示例来源:origin: stackoverflow.com
MimeBodyPart part = new MimeBodyPart();
part.addHeader("Content-Type", "application/pdf; charset=\"UTF-8\"; format=\"flowed\" ");
part.setFileName(MimeUtility.encodeText(file.getName(), "UTF-8", null));
//setDataHandler
代码示例来源:origin: org.eclipse.scout.rt/org.eclipse.scout.commons
/**
* Creates a single mime body part.
*
* @param bodyText
* Body text
* @param contentType
* Content type
* @return Crated mime body part
* @throws MessagingException
*/
private static MimeBodyPart createSingleBodyPart(String bodyText, String contentType) throws MessagingException {
MimeBodyPart part = new MimeBodyPart();
part.setText(bodyText, Encoding.UTF_8);
part.addHeader(CONTENT_TYPE_ID, contentType);
return part;
}
代码示例来源:origin: stackoverflow.com
String headerImageCid = "header";
InputStream pngInputStream = MailServiceImpl.class.getResourceAsStream("/images/" + headerImageCid + ".png");
DataSource ds = new ByteArrayDataSource(pngInputStream, "image/png");
MimeBodyPart imagePart = new MimeBodyPart();
imagePart.setDataHandler(new DataHandler(ds));
imagePart.setFileName(headerImageCid + ".png");
imagePart.setHeader("Content-Type", "image/png");
imagePart.addHeader("Content-ID", "<" + headerImageCid + ">");
final Multipart multipart = new MimeMultipart();
multipart.addBodyPart(textPart);
multipart.addBodyPart(htmlPart);
multipart.addBodyPart(imagePart);
msg.setContent(multipart);
msg.saveChanges();
Transport.send(msg);
代码示例来源:origin: OpenAS2/OpenAs2App
protected void addCustomOuterMimeHeaders(Message msg, MimeBodyPart dataBP) throws MessagingException
{
if (logger.isTraceEnabled())
{
logger.trace("Adding custom headers to outer MBP...." + msg.getLogMsgID());
}
Map<String, String> hdrs = msg.getCustomOuterMimeHeaders();
if (hdrs == null)
{
return;
}
for (Map.Entry<String, String> entry : hdrs.entrySet())
{
dataBP.addHeader(entry.getKey(), entry.getValue());
if (logger.isTraceEnabled())
{
logger.trace("Added custom headers to outer MBP: " + entry.getKey() + "--->" + entry.getValue() + msg.getLogMsgID());
}
}
}
代码示例来源:origin: stackoverflow.com
mbp2.addHeader("Content-Type", "text/plain; charset=\"UTF-8\"");
mbp2.addHeader("Content-Transfer-Encoding", "base64");
代码示例来源:origin: stackoverflow.com
"application/pkcs7-signature; name=smime.p7s", "base64");
attachPart.setFileName("smime.p7s");
attachPart.addHeader("Content-Description",
"S/MIME Cryptographic Signature");
代码示例来源:origin: stackoverflow.com
try {
MimeMessage m = new MimeMessage(getEmailSession());
InternetAddress[] to = new InternetAddress[] { new InternetAddress("mail@domain.com") };
m.setRecipients(Message.RecipientType.TO, to);
if (valideMail) {
m.setSender(new InternetAddress(user.getEmail()));
}
MimeMultipart multiPart = new MimeMultipart("mixed");
MimeBodyPart contentPart = new MimeBodyPart();
contentPart.setText("text", "UTF-8");
multiPart.addBodyPart(contentPart);
MimeBodyPart attachmentPart = new MimeBodyPart();
attachmentPart.setContent(emailEntity.getAttachment(), "application/png");
attachmentPart.addHeader("Content-Transfer-Encoding", "base64");
attachmentPart.setDisposition(Part.ATTACHMENT);
attachmentPart.setFileName(fileName);
multiPart.addBodyPart(attachmentPart);
m.setContent(multiPart);
//
Transport.send(m);
//
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
代码示例来源:origin: approvals/ApprovalTests.Java
/***********************************************************************/
public void addHTMLImage(String url, String fileName, InputStream inputStream) throws MessagingException
{
MimeBodyPart part = new MimeBodyPart();
url = url == null ? "" : url;
part.setDataHandler(new DataHandler(new ByteArrayDataSource(inputStream, "image/gif")));
// Define the encoding (choose between BASE64, UUENCODE, QUOTED-PRINTABLE)
part.setHeader("Content-Transfer-Encoding", "BASE64");
part.addHeader("Content-Location", url + fileName);
part.setFileName(fileName);
images.add(part);
}
/***********************************************************************/
代码示例来源:origin: axis/axis
/**
* Gets the header length for any part.
* @param bp the part to determine the header length for.
* @return the length in bytes.
*
* @throws javax.mail.MessagingException
* @throws java.io.IOException
*/
private static long getHeaderLength(javax.mail.internet.MimeBodyPart bp)
throws javax.mail.MessagingException, java.io.IOException {
javax.mail.internet.MimeBodyPart headersOnly =
new javax.mail.internet.MimeBodyPart(
new javax.mail.internet.InternetHeaders(), new byte[0]);
for (java.util.Enumeration en = bp.getAllHeaders();
en.hasMoreElements();) {
javax.mail.Header header = (javax.mail.Header) en.nextElement();
headersOnly.addHeader(header.getName(), header.getValue());
}
java.io.ByteArrayOutputStream bas =
new java.io.ByteArrayOutputStream(1024 * 16);
headersOnly.writeTo(bas);
bas.close();
return (long) bas.size(); // This has header length plus the crlf part that seperates the data
}
代码示例来源:origin: org.apache.axis/axis
/**
* Gets the header length for any part.
* @param bp the part to determine the header length for.
* @return the length in bytes.
*
* @throws javax.mail.MessagingException
* @throws java.io.IOException
*/
private static long getHeaderLength(javax.mail.internet.MimeBodyPart bp)
throws javax.mail.MessagingException, java.io.IOException {
javax.mail.internet.MimeBodyPart headersOnly =
new javax.mail.internet.MimeBodyPart(
new javax.mail.internet.InternetHeaders(), new byte[0]);
for (java.util.Enumeration en = bp.getAllHeaders();
en.hasMoreElements();) {
javax.mail.Header header = (javax.mail.Header) en.nextElement();
headersOnly.addHeader(header.getName(), header.getValue());
}
java.io.ByteArrayOutputStream bas =
new java.io.ByteArrayOutputStream(1024 * 16);
headersOnly.writeTo(bas);
bas.close();
return (long) bas.size(); // This has header length plus the crlf part that seperates the data
}
代码示例来源:origin: org.apache.axis/com.springsource.org.apache.axis
/**
* Gets the header length for any part.
* @param bp the part to determine the header length for.
* @return the length in bytes.
*
* @throws javax.mail.MessagingException
* @throws java.io.IOException
*/
private static long getHeaderLength(javax.mail.internet.MimeBodyPart bp)
throws javax.mail.MessagingException, java.io.IOException {
javax.mail.internet.MimeBodyPart headersOnly =
new javax.mail.internet.MimeBodyPart(
new javax.mail.internet.InternetHeaders(), new byte[0]);
for (java.util.Enumeration en = bp.getAllHeaders();
en.hasMoreElements();) {
javax.mail.Header header = (javax.mail.Header) en.nextElement();
headersOnly.addHeader(header.getName(), header.getValue());
}
java.io.ByteArrayOutputStream bas =
new java.io.ByteArrayOutputStream(1024 * 16);
headersOnly.writeTo(bas);
bas.close();
return (long) bas.size(); // This has header length plus the crlf part that seperates the data
}
代码示例来源:origin: org.codehaus.xfire/xfire-core
soapPart.setDataHandler(soapMessage.getDataHandler());
soapPart.setContentID("<"+soapMessage.getId()+">");
soapPart.addHeader("Content-Transfer-Encoding", "8bit");
mimeMP.addBodyPart(soapPart);
part.addHeader("Content-Transfer-Encoding", "binary");
代码示例来源:origin: org.kantega.openaksess/openaksess-core
private MimeBodyPart getMultimediaAsBodyPart(Integer mediaId) throws MessagingException {
MultimediaService multimediaService = new MultimediaService(SecuritySession.createNewAdminInstance());
Multimedia multimedia = multimediaService.getMultimedia(mediaId);
if (multimedia != null) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
multimediaService.streamMultimediaData(multimedia.getId(), new InputStreamHandler(bos));
MimeBodyPart bodyPart = MailSender.createMimeBodyPartFromData(bos.toByteArray(), multimedia.getMimeType().getType(), multimedia.getFilename());
bodyPart.addHeader("Content-ID", "<image" + multimedia.getId() + ">");
return bodyPart;
} else {
return null;
}
}
}
代码示例来源:origin: org.jboss.ws.native/jbossws-native-core
protected void addAttachmentParts(MimeMultipart multipart) throws SOAPException, MessagingException
{
Iterator attachmentParts = soapMessage.getAttachments();
while (attachmentParts.hasNext())
{
AttachmentPart attachmentPart = (AttachmentPart)attachmentParts.next();
DataHandler handler = attachmentPart.getDataHandler();
MimeBodyPart mimePart = new MimeBodyPart();
mimePart.setDataHandler(handler);
Iterator mimeHeaders = attachmentPart.getAllMimeHeaders();
while (mimeHeaders.hasNext())
{
MimeHeader soapHeader = (MimeHeader)mimeHeaders.next();
mimePart.addHeader(soapHeader.getName(), soapHeader.getValue());
}
if (mimePart.getHeader(MimeConstants.CONTENT_TYPE) == null)
{
String type = handler.getContentType();
mimePart.setHeader(MimeConstants.CONTENT_TYPE, (type != null) ? type : MimeConstants.TYPE_APPLICATION_OCTET_STREAM);
}
if (mimePart.getHeader(MimeConstants.CONTENT_ID) == null)
{
mimePart.setHeader(MimeConstants.CONTENT_ID, CIDGenerator.generateFromCount());
}
// TODO - Binary encoding is the most efficient, however, some transports (old mail servers)
// require 7 bit ascii. Can we ask the remoting layer about the transport's binary safety?
mimePart.setHeader(MimeConstants.CONTENT_TRANSFER_ENCODING, MimeConstants.BINARY_ENCODING);
multipart.addBodyPart(mimePart);
}
}
内容来源于网络,如有侵权,请联系作者删除!