热门标签 | 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);
}
}
}

推荐阅读
  • 使用圣杯布局模式实现网站首页的内容布局
    本文介绍了使用圣杯布局模式实现网站首页的内容布局的方法,包括HTML部分代码和实例。同时还提供了公司新闻、最新产品、关于我们、联系我们等页面的布局示例。商品展示区包括了车里子和农家生态土鸡蛋等产品的价格信息。 ... [详细]
  • 本文由编程笔记#小编为大家整理,主要介绍了logistic回归(线性和非线性)相关的知识,包括线性logistic回归的代码和数据集的分布情况。希望对你有一定的参考价值。 ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 本文介绍了在mac环境下使用nginx配置nodejs代理服务器的步骤,包括安装nginx、创建目录和文件、配置代理的域名和日志记录等。 ... [详细]
  • 本文介绍了机器学习手册中关于日期和时区操作的重要性以及其在实际应用中的作用。文章以一个故事为背景,描述了学童们面对老先生的教导时的反应,以及上官如在这个过程中的表现。同时,文章也提到了顾慎为对上官如的恨意以及他们之间的矛盾源于早年的结局。最后,文章强调了日期和时区操作在机器学习中的重要性,并指出了其在实际应用中的作用和意义。 ... [详细]
  • 本文详细介绍了如何使用MySQL来显示SQL语句的执行时间,并通过MySQL Query Profiler获取CPU和内存使用量以及系统锁和表锁的时间。同时介绍了效能分析的三种方法:瓶颈分析、工作负载分析和基于比率的分析。 ... [详细]
  • WhenIusepythontoapplythepymysqlmoduletoaddafieldtoatableinthemysqldatabase,itdo ... [详细]
  • Gitlab接入公司内部单点登录的安装和配置教程
    本文介绍了如何将公司内部的Gitlab系统接入单点登录服务,并提供了安装和配置的详细教程。通过使用oauth2协议,将原有的各子系统的独立登录统一迁移至单点登录。文章包括Gitlab的安装环境、版本号、编辑配置文件的步骤,并解决了在迁移过程中可能遇到的问题。 ... [详细]
  • 本文详细介绍了使用C#实现Word模版打印的方案。包括添加COM引用、新建Word操作类、开启Word进程、加载模版文件等步骤。通过该方案可以实现C#对Word文档的打印功能。 ... [详细]
  • 本文整理了Java中java.lang.NoSuchMethodError.getMessage()方法的一些代码示例,展示了NoSuchMethodErr ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文介绍了解决java开源项目apache commons email简单使用报错的方法,包括使用正确的JAR包和正确的代码配置,以及相关参数的设置。详细介绍了如何使用apache commons email发送邮件。 ... [详细]
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社区 版权所有