javax.mail.internet.MimeBodyPart.setHeader()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(200)

本文整理了Java中javax.mail.internet.MimeBodyPart.setHeader()方法的一些代码示例,展示了MimeBodyPart.setHeader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeBodyPart.setHeader()方法的具体详情如下:
包路径:javax.mail.internet.MimeBodyPart
类名称:MimeBodyPart
方法名:setHeader

MimeBodyPart.setHeader介绍

[英]Set the value for this header_name. Replaces all existing header values with this new value. 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: spring-projects/spring-framework

/**
 * Add an inline element to the MimeMessage, taking the content from a
 * {@code javax.activation.DataSource}.
 * <p>Note that the InputStream returned by the DataSource implementation
 * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke
 * {@code getInputStream()} multiple times.
 * <p><b>NOTE:</b> Invoke {@code addInline} <i>after</i> {@link #setText};
 * else, mail readers might not be able to resolve inline references correctly.
 * @param contentId the content ID to use. Will end up as "Content-ID" header
 * in the body part, surrounded by angle brackets: e.g. "myId" -> "&lt;myId&gt;".
 * Can be referenced in HTML source via src="cid:myId" expressions.
 * @param dataSource the {@code javax.activation.DataSource} to take
 * the content from, determining the InputStream and the content type
 * @throws MessagingException in case of errors
 * @see #addInline(String, java.io.File)
 * @see #addInline(String, org.springframework.core.io.Resource)
 */
public void addInline(String contentId, DataSource dataSource) throws MessagingException {
  Assert.notNull(contentId, "Content ID must not be null");
  Assert.notNull(dataSource, "DataSource must not be null");
  MimeBodyPart mimeBodyPart = new MimeBodyPart();
  mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
  // We're using setHeader here to remain compatible with JavaMail 1.2,
  // rather than JavaMail 1.3's setContentID.
  mimeBodyPart.setHeader(HEADER_CONTENT_ID, "<" + contentId + ">");
  mimeBodyPart.setDataHandler(new DataHandler(dataSource));
  getMimeMultipart().addBodyPart(mimeBodyPart);
}

代码示例来源:origin: org.springframework/spring-context-support

/**
 * Add an inline element to the MimeMessage, taking the content from a
 * {@code javax.activation.DataSource}.
 * <p>Note that the InputStream returned by the DataSource implementation
 * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke
 * {@code getInputStream()} multiple times.
 * <p><b>NOTE:</b> Invoke {@code addInline} <i>after</i> {@link #setText};
 * else, mail readers might not be able to resolve inline references correctly.
 * @param contentId the content ID to use. Will end up as "Content-ID" header
 * in the body part, surrounded by angle brackets: e.g. "myId" -> "&lt;myId&gt;".
 * Can be referenced in HTML source via src="cid:myId" expressions.
 * @param dataSource the {@code javax.activation.DataSource} to take
 * the content from, determining the InputStream and the content type
 * @throws MessagingException in case of errors
 * @see #addInline(String, java.io.File)
 * @see #addInline(String, org.springframework.core.io.Resource)
 */
public void addInline(String contentId, DataSource dataSource) throws MessagingException {
  Assert.notNull(contentId, "Content ID must not be null");
  Assert.notNull(dataSource, "DataSource must not be null");
  MimeBodyPart mimeBodyPart = new MimeBodyPart();
  mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
  // We're using setHeader here to remain compatible with JavaMail 1.2,
  // rather than JavaMail 1.3's setContentID.
  mimeBodyPart.setHeader(HEADER_CONTENT_ID, "<" + contentId + ">");
  mimeBodyPart.setDataHandler(new DataHandler(dataSource));
  getMimeMultipart().addBodyPart(mimeBodyPart);
}

代码示例来源:origin: apache/usergrid

MimeBodyPart plainPart = new MimeBodyPart();
plainPart.setContent( plainText, "text/plain" );
plainPart.setHeader( MIME_VERSION, "1.0" );
plainPart.setHeader( CONTENT_TYPE, "text/plain; charset=iso-8859-1" );
msgContent.addBodyPart( plainPart );
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent( htmlText, "text/html" );
htmlPart.setHeader( MIME_VERSION, "1.0" );
htmlPart.setHeader( CONTENT_TYPE, "text/html; charset=iso-8859-1" );
msgContent.addBodyPart( htmlPart );

代码示例来源:origin: igniterealtime/Openfire

html.setContent(htmlBody, "text/html; charset=UTF-8");
html.setDisposition(Part.INLINE);
html.setHeader("Content-Transfer-Encoding", "8bit");
content.addBodyPart(html);
bPart.setText(textBody, encoding);
bPart.setDisposition(Part.INLINE);
bPart.setHeader("Content-Transfer-Encoding", "8bit");
MimeMultipart mPart = new MimeMultipart();
mPart.addBodyPart(bPart);
bPart.setContent(htmlBody, "text/html; charset=UTF-8");
bPart.setDisposition(Part.INLINE);
bPart.setHeader("Content-Transfer-Encoding", "8bit");
MimeMultipart mPart = new MimeMultipart();
mPart.addBodyPart(bPart);

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Set the "Content-MD5" header field of this body part.
 *
 * @exception    IllegalWriteException if the underlying
 *            implementation does not support modification
 * @exception    IllegalStateException if this body part is
 *            obtained from a READ_ONLY folder.
 */
public void setContentMD5(String md5) throws MessagingException {
setHeader("Content-MD5", md5);
}

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * Set the "Content-MD5" header field of this body part.
 *
 * @exception    IllegalWriteException if the underlying
 *            implementation does not support modification
 * @exception    IllegalStateException if this body part is
 *            obtained from a READ_ONLY folder.
 */
@Override
public void setContentMD5(String md5) throws MessagingException {
setHeader("Content-MD5", md5);
}

代码示例来源:origin: pentaho/pentaho-kettle

messageBodyPart.setDataHandler( new DataHandler( fds ) );
messageBodyPart.setHeader( "Content-ID", "<" + realcontenID + ">" );

代码示例来源:origin: psi-probe/psi-probe

/**
 * Creates the message body part.
 *
 * @param body the body
 * @param html the html
 * @return the mime body part
 * @throws MessagingException the messaging exception
 */
private static MimeBodyPart createMessageBodyPart(String body, boolean html)
  throws MessagingException {
 MimeBodyPart bodyPart = new MimeBodyPart();
 bodyPart.setText(body);
 bodyPart.setHeader("content-type", html ? "text/html" : "text/plain");
 return bodyPart;
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Set the "Content-ID" header field of this body part.
 * If the <code>cid</code> parameter is null, any existing 
 * "Content-ID" is removed.
 *
 * @param    cid    the Content-ID
 * @exception    IllegalWriteException if the underlying
 *            implementation does not support modification
 * @exception    IllegalStateException if this body part is
 *            obtained from a READ_ONLY folder.
 * @exception    MessagingException for other failures
 * @since        JavaMail 1.3
 */
public void setContentID(String cid) throws MessagingException {
if (cid == null)
  removeHeader("Content-ID");
else
  setHeader("Content-ID", cid);
}

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * Set the "Content-ID" header field of this body part.
 * If the <code>cid</code> parameter is null, any existing 
 * "Content-ID" is removed.
 *
 * @param    cid    the Content-ID
 * @exception    IllegalWriteException if the underlying
 *            implementation does not support modification
 * @exception    IllegalStateException if this body part is
 *            obtained from a READ_ONLY folder.
 * @exception    MessagingException for other failures
 * @since        JavaMail 1.3
 */
public void setContentID(String cid) throws MessagingException {
if (cid == null)
  removeHeader("Content-ID");
else
  setHeader("Content-ID", cid);
}

代码示例来源:origin: rakam-io/rakam

String imageId = UUID.randomUUID().toString() + "@" +
    UUID.randomUUID().toString() + ".mail";
screenPart.setHeader("Content-ID", "<" + imageId + ">");

代码示例来源:origin: webx/citrus

private void renderInlineResource(Multipart multipart, InlineResource inlineResource, Set<String> fileNames)
    throws MessagingException {
  assertNotNull(resourceLoader, "no resourceLoader");
  String resourceName = inlineResource.getResourceName();
  Resource resource = resourceLoader.getResource(resourceName);
  if (!resource.exists()) {
    throw new MailBuilderException("Could not find resource \"" + resourceName + "\"");
  }
  DataSource ds;
  try {
    ds = new URLDataSource(resource.getURL());
  } catch (IOException e) {
    ds = new ResourceDataSource(resource);
  }
  MimeBodyPart bodyPart = new MimeBodyPart();
  bodyPart.setDataHandler(new DataHandler(ds));
  bodyPart.setHeader(CONTENT_ID, "<" + inlineResource.getContentId() + ">");
  bodyPart.setFileName(inlineResource.getUniqueFilename(fileNames));
  bodyPart.setDisposition("inline");
  multipart.addBodyPart(bodyPart);
}

代码示例来源:origin: webx/citrus

private void renderInlineResource(Multipart multipart, InlineResource inlineResource, Set<String> fileNames)
    throws MessagingException {
  assertNotNull(resourceLoader, "no resourceLoader");
  String resourceName = inlineResource.getResourceName();
  Resource resource = resourceLoader.getResource(resourceName);
  if (!resource.exists()) {
    throw new MailBuilderException("Could not find resource \"" + resourceName + "\"");
  }
  DataSource ds;
  try {
    ds = new URLDataSource(resource.getURL());
  } catch (IOException e) {
    ds = new ResourceDataSource(resource);
  }
  MimeBodyPart bodyPart = new MimeBodyPart();
  bodyPart.setDataHandler(new DataHandler(ds));
  bodyPart.setHeader(CONTENT_ID, "<" + inlineResource.getContentId() + ">");
  bodyPart.setFileName(inlineResource.getUniqueFilename(fileNames));
  bodyPart.setDisposition("inline");
  multipart.addBodyPart(bodyPart);
}

代码示例来源:origin: javax.mail/javax.mail-api

/**
 * Set the "Content-MD5" header field of this body part.
 *
 * @exception    IllegalWriteException if the underlying
 *            implementation does not support modification
 * @exception    IllegalStateException if this body part is
 *            obtained from a READ_ONLY folder.
 */
@Override
public void setContentMD5(String md5) throws MessagingException {
setHeader("Content-MD5", md5);
}

代码示例来源:origin: javax.mail/com.springsource.javax.mail

/**
 * Set the "Content-MD5" header field of this body part.
 *
 * @exception    IllegalWriteException if the underlying
 *            implementation does not support modification
 * @exception    IllegalStateException if this body part is
 *            obtained from a READ_ONLY folder.
 */
public void setContentMD5(String md5) throws MessagingException {
setHeader("Content-MD5", md5);
}

代码示例来源:origin: com.sun.mail/jakarta.mail

/**
 * Set the "Content-MD5" header field of this body part.
 *
 * @exception    IllegalWriteException if the underlying
 *            implementation does not support modification
 * @exception    IllegalStateException if this body part is
 *            obtained from a READ_ONLY folder.
 */
@Override
public void setContentMD5(String md5) throws MessagingException {
setHeader("Content-MD5", md5);
}

代码示例来源:origin: com.sun.mail/android-mail

/**
 * Set the "Content-MD5" header field of this body part.
 *
 * @exception    IllegalWriteException if the underlying
 *            implementation does not support modification
 * @exception    IllegalStateException if this body part is
 *            obtained from a READ_ONLY folder.
 */
@Override
public void setContentMD5(String md5) throws MessagingException {
setHeader("Content-MD5", md5);
}

代码示例来源:origin: pentaho/pentaho-kettle

imagePart.setDataHandler( new DataHandler( fds ) );
imagePart.setHeader( "Content-ID", "<" + contentID + ">" );

代码示例来源:origin: com.ibm.sbt/com.ibm.sbt.core

public MimeBodyPart toMimeBodyPart() throws MessagingException {
  MimeBodyPart bodyPart = new MimeBodyPart();
  bodyPart.setFileName(fileName);
  bodyPart.setContent(content, mimeType);
  bodyPart.setHeader("Content-Disposition", getDisposition());
  bodyPart.setHeader("Content-Type", mimeType);
  return bodyPart;
}

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

public void setDescription(String description, String charset) throws MessagingException {
  if (description == null) {
    removeHeader("Content-Description");
  }
  else {
    try {
      setHeader("Content-Description", MimeUtility.fold(21, MimeUtility.encodeText(description, charset, null)));
    } catch (UnsupportedEncodingException e) {
      throw new MessagingException(e.getMessage(), e);
    }
  }
}

相关文章