本文整理了Java中org.apache.james.mime4j.stream.Field
类的一些代码示例,展示了Field
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Field
类的具体详情如下:
包路径:org.apache.james.mime4j.stream.Field
类名称:Field
[英]This interface represents an abstract MIME field. A MIME field must have a non null
name and a content body (unfolded but unparsed and possibly encoded). Optionally implementing classes may also retain the original (raw) representation in a form of ByteSequence.
Specific implementations of this interface may also use a richer model to represent the field if its body can be parsed into a set of constituent elements.
[中]此接口表示一个抽象MIME字段。MIME字段必须具有非null
名称和内容正文(展开但未分析,可能已编码)。可选地,实现类还可以以字节顺序的形式保留原始(原始)表示。
如果字段的主体可以解析为一组组成元素,则此接口的特定实现也可以使用更丰富的模型来表示字段。
代码示例来源:origin: k9mail/k-9
@Override
public void field(Field parsedField) throws MimeException {
String name = parsedField.getName();
String raw = parsedField.getRaw().toString();
Part part = (Part) stack.peek();
part.addRawHeader(name, raw);
String fieldImmediateValue = MimeUtility.getHeaderParameter(parsedField.getBody(), null);
if ("Content-Type".equalsIgnoreCase(name) && MimeUtility.isMessage(fieldImmediateValue)) {
isMessagePart = true;
}
if ("Content-Disposition".equalsIgnoreCase(name) && "attachment".equalsIgnoreCase(fieldImmediateValue)) {
isContentDispositionAttachment = true;
}
}
代码示例来源:origin: k9mail/k-9
@Override
public void field(Field rawField) throws MimeException {
String name = rawField.getName();
String raw = rawField.getRaw().toString();
part.addRawHeader(name, raw);
}
代码示例来源:origin: apache/tika
String fieldname = field.getName();
} else {
metadata.add(Metadata.MESSAGE_RAW_HEADER_PREFIX + parsedField.getName(),
field.getBody());
Date date = dateField.getDate();
if (date == null) {
date = tryOtherDateFormats(field.getBody());
field.getBody());
代码示例来源:origin: org.apache.james/apache-mime4j-dom
/**
* Gets the unfolded, unparsed and possibly encoded (see RFC 2047) field
* body string.
*
* @return the unfolded unparsed field body string.
*/
public String getBody() {
return rawField.getBody();
}
代码示例来源:origin: org.apache.james/apache-mime4j-dom
/**
* Gets the name of the field (<code>Subject</code>,
* <code>From</code>, etc).
*
* @return the field name.
*/
public String getName() {
return rawField.getName();
}
代码示例来源:origin: apache/tika
private String stripOutFieldPrefix(Field field, String fieldname) {
String temp = field.getRaw().toString();
int loc = fieldname.length();
while (temp.charAt(loc) == ' ') {
loc++;
}
return temp.substring(loc);
}
代码示例来源:origin: org.apache.james/apache-mime4j-dom
protected RawField getRawField() {
if (rawField instanceof RawField) {
return ((RawField) rawField);
} else {
return new RawField(rawField.getName(), rawField.getBody());
}
}
代码示例来源:origin: org.apache.james/apache-mime4j-dom
/**
* Returns the value of the <i>Message-ID</i> header field of this message
* or <code>null</code> if it is not present.
*
* @return the identifier of this message.
*/
public String getMessageId() {
Field field = obtainField(FieldName.MESSAGE_ID);
return field != null ? field.getBody() : null;
}
代码示例来源:origin: org.apache.james/apache-mime4j-dom
/**
* Adds a field to the end of the list of fields.
*
* @param field the field to add.
*/
public void addField(Field field) {
List<Field> values = fieldMap.get(field.getName().toLowerCase(Locale.US));
if (values == null) {
values = new LinkedList<Field>();
fieldMap.put(field.getName().toLowerCase(Locale.US), values);
}
values.add(field);
fields.add(field);
}
代码示例来源:origin: k9mail/k-9
@Override
public void field(Field parsedField) throws MimeException {
expect(Part.class);
String name = parsedField.getName();
String raw = parsedField.getRaw().toString();
((Part) stack.peek()).addRawHeader(name, raw);
}
}
代码示例来源:origin: org.apache.james/apache-mime4j-dom
/**
* Gets original (raw) representation of the field, if available,
* <code>null</code> otherwise.
*/
public ByteSequence getRaw() {
return rawField.getRaw();
}
代码示例来源:origin: org.apache.james/apache-james-mailbox-elasticsearch
public Builder add(Field field) {
Preconditions.checkNotNull(field);
String headerName = field.getName().toLowerCase(Locale.US);
String sanitizedValue = MimeUtil.unscrambleHeaderValue(field.getBody());
if (!headerName.contains(".")) {
headers.put(headerName, sanitizedValue);
}
handleSpecificHeader(headerName, sanitizedValue);
return this;
}
代码示例来源:origin: org.apache.james/apache-mime4j-dom
/**
* Write the specified <code>Field</code> to the specified
* <code>OutputStream</code>.
*
* @param field
* the <code>Field</code> to write.
* @param out
* the OutputStream to write to.
* @throws IOException
* if an I/O error occurs.
*/
public void writeField(Field field, OutputStream out) throws IOException {
ByteSequence raw = field.getRaw();
if (raw == null) {
StringBuilder buf = new StringBuilder();
buf.append(field.getName());
buf.append(": ");
String body = field.getBody();
if (body != null) {
buf.append(body);
}
raw = ContentUtil.encode(MimeUtil.fold(buf.toString(), 0));
}
writeBytes(raw, out);
out.write(CRLF);
}
代码示例来源:origin: org.apache.james/apache-mime4j-dom
/**
* Returns the value of the <i>Message-ID</i> header field of this message
* or <code>null</code> if it is not present.
*
* @return the identifier of this message.
*/
public String getMessageId() {
Field field = obtainField(FieldName.MESSAGE_ID);
if (field == null)
return null;
return field.getBody();
}
代码示例来源:origin: org.apache.james/apache-mime4j-dom
/**
* Adds a field to the end of the list of fields.
*
* @param field the field to add.
*/
public AbstractEntityBuilder addField(Field field) {
List<Field> values = fieldMap.get(field.getName().toLowerCase(Locale.US));
if (values == null) {
values = new LinkedList<Field>();
fieldMap.put(field.getName().toLowerCase(Locale.US), values);
}
values.add(field);
fields.add(field);
return this;
}
代码示例来源:origin: com.github.lafa.tikaNoExternal/tika-parsers
private String stripOutFieldPrefix(Field field, String fieldname) {
String temp = field.getRaw().toString();
int loc = fieldname.length();
while (temp.charAt(loc) == ' ') {
loc++;
}
return temp.substring(loc);
}
代码示例来源:origin: org.jwall/org.jwall.web.audit
@Override
public void field(Field rawField) throws MimeException {
log.debug("field( {} )", rawField);
currentSection.append(rawField.getName() + ": "
+ rawField.getBody());
currentSection.append("\r\n");
if ("Content-Disposition".equals(rawField.getName())) {
String line = rawField.getBody();
int idx = line.indexOf("name=\"");
if (idx > 0) {
idx += "name=\"".length();
int end = line.indexOf("\"", idx);
if (end > 0) {
name = line.substring(idx, end);
log.debug("Diving into section '{}'", name);
}
}
}
if ("Content-Type".equals(rawField.getName())) {
int idx = rawField.getBody().indexOf("boundary=");
if (idx > 0) {
boundary = rawField.getBody().substring(
idx + "boundary=".length());
log.debug("Boundary is '{}'", boundary);
}
}
}
代码示例来源:origin: org.apache.james/apache-james-mailbox-store
@Override
public void field(Field field) throws MimeException {
String fieldValue;
if (field instanceof RawField) {
// check if we can access the body in the raw form so no unfolding was done under the hood
ByteSequence raw = field.getRaw();
int len = raw.length();
int off = ((RawField) field).getDelimiterIdx() + 1;
if (len > off + 1 && (raw.byteAt(off) & 0xff) == 0x20) {
off++;
}
fieldValue = ContentUtil.decode(raw, off, len - off);
} else {
fieldValue = field.getBody();
}
if (fieldValue.endsWith("\r\f")) {
fieldValue = fieldValue.substring(0,fieldValue.length() - 2);
}
if (fieldValue.startsWith(" ")) {
fieldValue = fieldValue.substring(1);
}
final ResultHeader resultHeader = new ResultHeader(field.getName(), fieldValue);
results.add(resultHeader);
}
});
代码示例来源:origin: org.apache.james/apache-mime4j-james-utils
private boolean checkHeader(final CharBuffer buffer, MimeTokenStream parser) throws IOException {
final String value = parser.getField().getBody();
final StringReader reader = new StringReader(value);
return isFoundIn(reader, buffer);
}
代码示例来源:origin: org.apache.james/apache-mime4j-dom
/**
* Removes all <code>Field</code>s having the specified field name.
*
* @param name
* the field name (e.g. From, Subject).
*/
public AbstractEntityBuilder removeFields(String name) {
final String lowerCaseName = name.toLowerCase(Locale.US);
List<Field> removed = fieldMap.remove(lowerCaseName);
if (removed == null || removed.isEmpty()) {
return this;
}
for (Iterator<Field> iterator = fields.iterator(); iterator.hasNext();) {
Field field = iterator.next();
if (field.getName().equalsIgnoreCase(name)) {
iterator.remove();
}
}
return this;
}
内容来源于网络,如有侵权,请联系作者删除!