本文整理了Java中org.apache.james.mime4j.stream.Field.getName()
方法的一些代码示例,展示了Field.getName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Field.getName()
方法的具体详情如下:
包路径:org.apache.james.mime4j.stream.Field
类名称:Field
方法名:getName
[英]Returns the name of the field.
[中]返回字段的名称。
代码示例来源: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: 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: 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: 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
String fieldname = field.getName();
代码示例来源: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: 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: 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;
}
代码示例来源: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).
* @return number of fields removed.
*/
public int removeFields(String name) {
final String lowerCaseName = name.toLowerCase(Locale.US);
List<Field> removed = fieldMap.remove(lowerCaseName);
if (removed == null || removed.isEmpty())
return 0;
for (Iterator<Field> iterator = fields.iterator(); iterator.hasNext();) {
Field field = iterator.next();
if (field.getName().equalsIgnoreCase(name))
iterator.remove();
}
return removed.size();
}
代码示例来源: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
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
public ParsedField parse(final Field rawField, final DecodeMonitor monitor) {
final FieldParser<? extends ParsedField> parser = getParser(rawField.getName());
return parser.parse(rawField, monitor);
}
}
代码示例来源:origin: org.apache.james/apache-mime4j-examples
/**
* Create a node given a Multipart body.
* Add the Preamble, all Body parts and the Epilogue to the node.
*
* @return the root node of the tree.
*/
private DefaultMutableTreeNode createNode(Header header) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(
new ObjectWrapper("Header", header));
for (Field field : header.getFields()) {
String name = field.getName();
node.add(new DefaultMutableTreeNode(new ObjectWrapper(name, field)));
}
return node;
}
代码示例来源: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.ws.commons.axiom/axiom-api
private List readHeaders() throws IOException, MimeException {
if(log.isDebugEnabled()){
log.debug("readHeaders");
}
checkParserState(parser.next(), EntityState.T_START_HEADER);
List headers = new ArrayList();
while (parser.next() == EntityState.T_FIELD) {
Field field = parser.getField();
String name = field.getName();
String value = field.getBody();
if (log.isDebugEnabled()){
log.debug("addHeader: (" + name + ") value=(" + value +")");
}
headers.add(new Header(name, value));
}
checkParserState(parser.next(), EntityState.T_BODY);
return headers;
}
代码示例来源:origin: org.apache.james/apache-james-mailbox-store
private static MimeDescriptorImpl createDescriptor(
final MimeTokenStream parser) throws IOException, MimeException {
EntityState next = parser.next();
final Collection<MessageResult.Header> headers = new ArrayList<>();
while (next != EntityState.T_BODY
&& next != EntityState.T_END_OF_STREAM
&& next != EntityState.T_START_MULTIPART) {
if (next == EntityState.T_FIELD) {
headers.add(new ResultHeader(parser.getField().getName(), parser
.getField().getBody().trim()));
}
next = parser.next();
}
final MimeDescriptorImpl mimeDescriptorImpl;
switch (next) {
case T_BODY:
mimeDescriptorImpl = simplePartDescriptor(parser, headers);
break;
case T_START_MULTIPART:
mimeDescriptorImpl = compositePartDescriptor(parser, headers);
break;
case T_END_OF_STREAM:
throw new MimeException("Premature end of stream");
default:
throw new MimeException("Unexpected parse state");
}
return mimeDescriptorImpl;
}
代码示例来源:origin: uk.gov.dstl.baleen/baleen-collectionreaders
/** Process a multipart body part */
private boolean processMultipart(JCas jCas, Multipart mp, String sourceUri) throws IOException {
boolean doneBody = false;
for (Entity e : mp.getBodyParts()) {
if (e.getFilename() != null) {
// Part has a filename, and is therefore an attachment
String extension = FilenameUtils.getExtension(e.getFilename()).toLowerCase();
if (ignoreExtensionsList.contains(extension)) {
getMonitor().info("Skipping attachment {}", e.getFilename());
continue;
}
attachments.put(sourceUri + "/" + e.getFilename(), e.getBody());
} else if (!doneBody) {
// Part has no filename, and we've not already processed a part to use as a body
processBody(jCas, e.getBody(), sourceUri);
// Add metadata
for (Field f : e.getParent().getHeader().getFields()) {
addMetadata(jCas, f.getName(), f.getBody());
}
doneBody = true;
}
}
return doneBody;
}
代码示例来源:origin: dstl/baleen
/** Process a multipart body part */
private boolean processMultipart(JCas jCas, Multipart mp, String sourceUri) throws IOException {
boolean doneBody = false;
for (Entity e : mp.getBodyParts()) {
if (e.getFilename() != null) {
// Part has a filename, and is therefore an attachment
String extension = FilenameUtils.getExtension(e.getFilename()).toLowerCase();
if (ignoreExtensionsList.contains(extension)) {
getMonitor().info("Skipping attachment {}", e.getFilename());
continue;
}
attachments.put(sourceUri + "/" + e.getFilename(), e.getBody());
} else if (!doneBody) {
// Part has no filename, and we've not already processed a part to use as a body
processBody(jCas, e.getBody(), sourceUri);
// Add metadata
for (Field f : e.getParent().getHeader().getFields()) {
addMetadata(jCas, f.getName(), f.getBody());
}
doneBody = true;
}
}
return doneBody;
}
代码示例来源:origin: dstl/baleen
/** Process a single body part */
private boolean processBody(JCas jCas, Body body, String sourceUri) throws IOException {
if (body instanceof TextBody) {
// Process plain text body
processTextBody(jCas, (TextBody) body);
// Add fields from parent
for (Field f : body.getParent().getHeader().getFields()) {
addMetadata(jCas, f.getName(), f.getBody());
}
// Set up document annotation - this is done by the content extractor in other cases
DocumentAnnotation doc = UimaSupport.getDocumentAnnotation(jCas);
doc.setSourceUri(sourceUri);
doc.setTimestamp(System.currentTimeMillis());
} else if (body instanceof BinaryBody) {
processBinaryBody(jCas, (BinaryBody) body, sourceUri);
} else if (body instanceof Multipart) {
// Multipart message, so recurse
Multipart mp = (Multipart) body;
return processMultipart(jCas, mp, sourceUri);
} else {
// No body processed
return false;
}
return true;
}
代码示例来源:origin: uk.gov.dstl.baleen/baleen-collectionreaders
/** Process a single body part */
private boolean processBody(JCas jCas, Body body, String sourceUri) throws IOException {
if (body instanceof TextBody) {
// Process plain text body
processTextBody(jCas, (TextBody) body);
// Add fields from parent
for (Field f : body.getParent().getHeader().getFields()) {
addMetadata(jCas, f.getName(), f.getBody());
}
// Set up document annotation - this is done by the content extractor in other cases
DocumentAnnotation doc = UimaSupport.getDocumentAnnotation(jCas);
doc.setSourceUri(sourceUri);
doc.setTimestamp(System.currentTimeMillis());
} else if (body instanceof BinaryBody) {
processBinaryBody(jCas, (BinaryBody) body, sourceUri);
} else if (body instanceof Multipart) {
// Multipart message, so recurse
Multipart mp = (Multipart) body;
return processMultipart(jCas, mp, sourceUri);
} else {
// No body processed
return false;
}
return true;
}
内容来源于网络,如有侵权,请联系作者删除!