@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; } }
/** * 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(); }
/** * Gets the name of the field (<code>Subject</code>, * <code>From</code>, etc). * * @return the field name. */ public String getName() { return rawField.getName(); }
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); }
/** * 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; }
/** * 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); }
/** * Gets original (raw) representation of the field, if available, * <code>null</code> otherwise. */ public ByteSequence getRaw() { return rawField.getRaw(); }
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; }
/** * 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); }
/** * 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(); }
/** * 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; }
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); }
@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); } } }
@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); } });
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); }
/** * 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; }