/** * Encode an address header, and perform folding if needed. * * @param sb The stringBuilder to write to * @param headerName The RFC 2822 header name * @param addresses the reformatted address substrings to encode. */ public void encodeHeaderAddresses( StringBuilder sb, String headerName, ArrayList<Rfc822Token> addresses) { /* TODO: Do we need to encode the addresses if they contain illegal characters? * This depends of the outcome of errata 4176. The current spec. states to use UTF-8 * where possible, but the RFCs states to use US-ASCII for the headers - hence encoding * would be needed to support non US-ASCII characters. But the MAP spec states not to * use any encoding... */ int partLength, lineLength = 0; lineLength += headerName.getBytes().length; sb.append(headerName); for (Rfc822Token address : addresses) { partLength = address.toString().getBytes().length + 1; // Add folding if needed if (lineLength + partLength >= 998) // max line length in RFC2822 { sb.append("\r\n "); // Append a FWS (folding whitespace) lineLength = 0; } sb.append(address.toString()).append(";"); lineLength += partLength; } sb.append("\r\n"); }