热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

本文整理了Java中javax.mail.internet.MimeUtility.fold()方法的一些代码示例,展示了MimeUtility.fold(

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

MimeUtility.fold介绍

[英]Fold a string at linear whitespace so that each line is no longer than 76 characters, if possible. If there are more than 76 non-whitespace characters consecutively, the string is folded at the first whitespace after that sequence. The parameter used indicates how many characters have been used in the current line; it is usually the length of the header name.

Note that line breaks in the string aren't escaped; they probably should be.
[中]如果可能的话,以线性空白折叠字符串,使每行长度不超过76个字符。如果连续有超过76个非空白字符,字符串将在该序列后的第一个空白处折叠。参数used表示当前行中使用了多少个字符;它通常是标题名的长度。
请注意,字符串中的换行符不会被转义;他们可能应该这样。

代码示例

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

public void addNV(String name, String value) {
sb.append("; ");
used += 2;
int len = name.length() + value.length() + 1;
if (used + len > 76) { // overflows ...
sb.append("\r\n\t"); // .. start new continuation line
used = 8; // account for the starting char
}
sb.append(name).append('=');
used += name.length() + 1;
if (used + value.length() > 76) { // still overflows ...
// have to fold value
String s = MimeUtility.fold(used, value);
sb.append(s);
int lastlf = s.lastIndexOf('\n');
if (lastlf >= 0) // always true
used += s.length() - lastlf - 1;
else
used += s.length();
} else {
sb.append(value);
used += value.length();
}
}

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

public void addNV(String name, String value) {
sb.append("; ");
used += 2;
int len = name.length() + value.length() + 1;
if (used + len > 76) { // overflows ...
sb.append("\r\n\t"); // .. start new continuation line
used = 8; // account for the starting char
}
sb.append(name).append('=');
used += name.length() + 1;
if (used + value.length() > 76) { // still overflows ...
// have to fold value
String s = MimeUtility.fold(used, value);
sb.append(s);
int lastlf = s.lastIndexOf('\n');
if (lastlf >= 0) // always true
used += s.length() - lastlf - 1;
else
used += s.length();
} else {
sb.append(value);
used += value.length();
}
}

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

/**
* Create a folded header value containing 76 character chunks.
*
* @param name the name of the header
* @param value the value of the header
* @return the folded header value
* @throws IllegalArgumentException if either the name or value is null or empty
*/
private String createFoldedHeaderValue(final String name, final String value)
{
if (EmailUtils.isEmpty(name))
{
throw new IllegalArgumentException("name can not be null or empty");
}
if (value == null || EmailUtils.isEmpty(value))
{
throw new IllegalArgumentException("value can not be null or empty");
}
try
{
return MimeUtility.fold(name.length() + 2, MimeUtility.encodeText(value, this.charset, null));
}
catch (final UnsupportedEncodingException e)
{
return value;
}
}

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

String s = MimeUtility.fold(0, addresses[i].toString());
int len = lengthOfFirstSegment(s); // length till CRLF
if (used + len > 76) { // overflows ...

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

/**
* Sets the x-mailer header.
* @param msg the target message.
*/
private void setMailer(final Message msg) {
try {
final Class mail = MailHandler.class;
final Class k = getClass();
String value;
if (k == mail) {
value = mail.getName();
} else {
try {
value = MimeUtility.encodeText(k.getName());
} catch (final UnsupportedEncodingException E) {
reportError(E.getMessage(), E, ErrorManager.FORMAT_FAILURE);
value = k.getName().replaceAll("[^\\x00-\\x7F]", "\uu001A");
}
value = MimeUtility.fold(10, mail.getName() + " using the "
+ value + " extension.");
}
msg.setHeader("X-Mailer", value);
} catch (final MessagingException ME) {
reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
}
}

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

String s = MimeUtility.fold(0, addresses[i].toString());
int len = lengthOfFirstSegment(s); // length till CRLF
if (used + len > 76) { // overflows ...

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

/**
* Sets the x-mailer header.
* @param msg the target message.
*/
private void setMailer(final Message msg) {
try {
final Class mail = MailHandler.class;
final Class k = getClass();
String value;
if (k == mail) {
value = mail.getName();
} else {
try {
value = MimeUtility.encodeText(k.getName());
} catch (final UnsupportedEncodingException E) {
reportError(E.getMessage(), E, ErrorManager.FORMAT_FAILURE);
value = k.getName().replaceAll("[^\\x00-\\x7F]", "\uu001A");
}
value = MimeUtility.fold(10, mail.getName() + " using the "
+ value + " extension.");
}
msg.setHeader("X-Mailer", value);
} catch (final MessagingException ME) {
reportError(ME.getMessage(), ME, ErrorManager.FORMAT_FAILURE);
}
}

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

StandardCharsets.ISO_8859_1);
String s = MimeUtility.fold(0, as);
int len = lengthOfFirstSegment(s); // length till CRLF
if (used + len > 76) { // overflows ...

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

/**
* Set the RFC 822 "From" header field. Any existing values are
* replaced with the given address. If address is null,
* this header is removed.
*
* @param address the sender of this message
* @exception IllegalWriteException if the underlying
* implementation does not support modification
* of existing values
* @exception IllegalStateException if this message is
* obtained from a READ_ONLY folder.
* @exception MessagingException for other failures
*/
public void setFrom(Address address) throws MessagingException {
if (address == null)
removeHeader("From");
else
setHeader("From", MimeUtility.fold(6, address.toString()));
}

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

/**
* Set the RFC 822 "Sender" header field. Any existing values are
* replaced with the given address. If address is null,
* this header is removed.
*
* @param address the sender of this message
* @exception IllegalWriteException if the underlying
* implementation does not support modification
* of existing values
* @exception IllegalStateException if this message is
* obtained from a READ_ONLY folder.
* @exception MessagingException for other failures
* @since JavaMail 1.3
*/
public void setSender(Address address) throws MessagingException {
if (address == null)
removeHeader("Sender");
else
setHeader("Sender", MimeUtility.fold(8, address.toString()));
}

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

/**
* Set the RFC 822 "From" header field. Any existing values are
* replaced with the given address. If address is null,
* this header is removed.
*
* @param address the sender of this message
* @exception IllegalWriteException if the underlying
* implementation does not support modification
* of existing values
* @exception IllegalStateException if this message is
* obtained from a READ_ONLY folder.
* @exception MessagingException for other failures
*/
@Override
public void setFrom(Address address) throws MessagingException {
if (address == null)
removeHeader("From");
else
setHeader("From", MimeUtility.fold(6, address.toString()));
}

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

/**
* Set the RFC 822 "Sender" header field. Any existing values are
* replaced with the given address. If address is null,
* this header is removed.
*
* @param address the sender of this message
* @exception IllegalWriteException if the underlying
* implementation does not support modification
* of existing values
* @exception IllegalStateException if this message is
* obtained from a READ_ONLY folder.
* @exception MessagingException for other failures
* @since JavaMail 1.3
*/
public void setSender(Address address) throws MessagingException {
if (address == null)
removeHeader("Sender");
else
setHeader("Sender", MimeUtility.fold(8, address.toString()));
}

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

static void
setDescription(MimePart part, String description, String charset)
throws MessagingException {
if (description == null) {
part.removeHeader("Content-Description");
return;
}
try {
part.setHeader("Content-Description", MimeUtility.fold(21,
MimeUtility.encodeText(description, charset, null)));
} catch (UnsupportedEncodingException uex) {
throw new MessagingException("Encoding error", uex);
}
}

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

static void
setDescription(MimePart part, String description, String charset)
throws MessagingException {
if (description == null) {
part.removeHeader("Content-Description");
return;
}
try {
part.setHeader("Content-Description", MimeUtility.fold(21,
MimeUtility.encodeText(description, charset, null)));
} catch (UnsupportedEncodingException uex) {
throw new MessagingException("Encoding error", uex);
}
}

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

} else {
try {
setHeader("Subject", MimeUtility.fold(9,
MimeUtility.encodeText(subject, charset, null)));
} catch (UnsupportedEncodingException uex) {

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

} else {
try {
setHeader("Subject", MimeUtility.fold(9,
MimeUtility.encodeText(subject, charset, null)));
} catch (UnsupportedEncodingException uex) {

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

reply.setHeader("References", MimeUtility.fold(12, refs));

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

reply.setHeader("References", MimeUtility.fold(12, refs));

代码示例来源:origin: com.aliyun/aliyun-java-sdk-dm

private void setHeader(Email email, Message message) throws UnsupportedEncodingException, MessagingException {
if(email.getTemplateContent() != null && email.getTemplateContent().length() > 0) {
email.getHeaders().put(X_SMTP_TRANS_PARAM, email.getTemplateContent());
}
for(Map.Entry header : email.getHeaders().entrySet()) {
String name = header.getKey();
String value = MimeUtility.encodeText(header.getValue(), EMAIL_ENCODING, null);
String foldedHeaderValue = MimeUtility.fold(name.length() + 2, value);
message.addHeader(header.getKey(), foldedHeaderValue);
}
}
}

代码示例来源: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);
}
}
}

推荐阅读
  • 本文详细介绍了Oracle 11g中的创建表空间的方法,以及如何设置客户端和服务端的基本配置,包括用户管理、环境变量配置等。 ... [详细]
  • 处理Android EditText中数字输入与parseInt方法
    本文探讨了如何在Android应用中从EditText组件安全地获取并解析用户输入的数字,特别是用于设置端口号的情况。通过示例代码和异常处理策略,展示了有效的方法来避免因非法输入导致的应用崩溃。 ... [详细]
  • 本文详细介绍了如何使用C#实现不同类型的系统服务账户(如Windows服务、计划任务和IIS应用池)的密码重置方法。 ... [详细]
  • 在开发过程中,有时需要提供用户创建数据库的功能。本文介绍了如何利用 .NET 和 ADOX 在应用程序中实现创建 Access 数据库,并详细说明了创建数据库及表的具体步骤。 ... [详细]
  • 本文回顾了作者在求职阿里和腾讯实习生过程中,从最初的迷茫到最后成功获得Offer的心路历程。文中不仅分享了个人的面试经历,还提供了宝贵的面试准备建议和技巧。 ... [详细]
  • binlog2sql,你该知道的数据恢复工具
    binlog2sql,你该知道的数据恢复工具 ... [详细]
  • 在Android中实现黑客帝国风格的数字雨效果
    本文将详细介绍如何在Android平台上利用自定义View实现类似《黑客帝国》中的数字雨效果。通过实例代码,我们将探讨如何设置文字颜色、大小,以及如何控制数字下落的速度和间隔。 ... [详细]
  • 本文探讨了Python类型注解使用率低下的原因,主要归结于历史背景和投资回报率(ROI)的考量。文章不仅分析了类型注解的实际效用,还回顾了Python类型注解的发展历程。 ... [详细]
  • 在1995年,Simon Plouffe 发现了一种特殊的求和方法来表示某些常数。两年后,Bailey 和 Borwein 在他们的论文中发表了这一发现,这种方法被命名为 Bailey-Borwein-Plouffe (BBP) 公式。该问题要求计算圆周率 π 的第 n 个十六进制数字。 ... [详细]
  • 编码unicode解决了语言不通的问题.但是.unicode又有一个新问题.由于unicode是万国码.把所有国家的文字都编进去了.这就导致一个unicode占用的空间会很大.原来 ... [详细]
  • 本文基于Java官方文档进行了适当修改,旨在介绍如何实现一个能够同时处理多个客户端请求的服务端程序。在前文中,我们探讨了单客户端访问的服务端实现,而本篇将深入讲解多客户端环境下的服务端设计与实现。 ... [详细]
  • ArcBlock 发布 ABT 节点 1.0.31 版本更新
    2020年11月9日,ArcBlock 区块链基础平台发布了 ABT 节点开发平台的1.0.31版本更新,此次更新带来了多项功能增强与性能优化。 ... [详细]
  • ASP.NET 进度条实现详解
    本文介绍了如何在ASP.NET中使用HTML和JavaScript创建一个动态更新的进度条,并通过Default.aspx页面进行展示。 ... [详细]
  • Hanks博士是一位著名的生物技术专家,他的儿子Hankson对数学有着浓厚的兴趣。最近,Hankson遇到了一个有趣的数学问题,涉及求解特定条件下的正整数x,而不使用传统的辗转相除法。 ... [详细]
  • Maven + Spring + MyBatis + MySQL 环境搭建与实例解析
    本文详细介绍如何使用MySQL数据库进行环境搭建,包括创建数据库表并插入示例数据。随后,逐步指导如何配置Maven项目,整合Spring框架与MyBatis,实现高效的数据访问。 ... [详细]
author-avatar
记忆里的Angle
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有