/** * Sets headers on this message. The expected format of each header is key: value. * * @param headers */ public void setHeaders(List<String> headers) { if (headers != null) { for (String header : headers) { int splitPoint = header.indexOf(":"); String key = header.substring(0, splitPoint); String value = null; if (splitPoint != header.length() - 1) { value = header.substring(splitPoint + 1).trim(); } setHeader(key, value); } } }
message.setHeader("multipart-subtype", "alternative");
/** * Sets headers on this message. The expected format of each header is key: value. * * @param headers */ public void setHeaders(List<String> headers) { if (headers != null) { for (String header : headers) { int splitPoint = header.indexOf(":"); String key = header.substring(0, splitPoint); String value = null; if (splitPoint != header.length() - 1) { value = header.substring(splitPoint + 1).trim(); } setHeader(key, value); } } }
/** * Add a header to this message. If the key is found in the headers of this message, the value * is appended to the previous value found and separated by a space. A key of null will not be * added. If value is null, previous entries of the matching key will be removed. * * @param key * The key of the header. * @param value * The value of the header. */ public void addHeader(String key, String value) { if (headers == null || headers.get(key) == null) { setHeader(key, value); } else if (key != null && value != null) { String prevVal = headers.get(key); prevVal += " " + value; headers.put(key, prevVal); } else if (value == null) { removeHeader(key); } }
/** * Add a header to this message. If the key is found in the headers of this message, the value * is appended to the previous value found and separated by a space. A key of null will not be * added. If value is null, previous entries of the matching key will be removed. * * @param key * The key of the header. * @param value * The value of the header. */ public void addHeader(String key, String value) { if (headers == null || headers.get(key) == null) { setHeader(key, value); } else if (key != null && value != null) { String prevVal = headers.get(key); prevVal += " " + value; headers.put(key, prevVal); } else if (value == null) { removeHeader(key); } }