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