01: /*
02: * MailUtilities.java
03: *
04: * Copyright (C) 2000-2003 Peter Graves
05: * $Id: MailUtilities.java,v 1.2 2003/03/09 14:01:01 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.j.mail;
23:
24: import java.util.List;
25: import org.armedbear.j.FastStringBuffer;
26: import org.armedbear.j.Utilities;
27:
28: public class MailUtilities {
29: public static String constructAddressHeader(String prefix, List list) {
30: return constructAddressHeader(prefix, list, 8);
31: }
32:
33: public static String constructAddressHeader(String prefix,
34: List list, int indent) {
35: FastStringBuffer sb = new FastStringBuffer(prefix);
36: int length = prefix.length();
37: if (list != null) {
38: for (int i = 0; i < list.size(); i++) {
39: MailAddress a = (MailAddress) list.get(i);
40: String s = a.toEncodedString();
41: if (i > 0 && length + s.length() > 74) {
42: // Won't fit on current line.
43: sb.append(',');
44: sb.append('\n');
45: sb.append(Utilities.spaces(indent)); // Continuation.
46: sb.append(s);
47: length = indent + s.length();
48: } else {
49: if (i > 0) {
50: sb.append(", ");
51: length += 2;
52: }
53: sb.append(s);
54: length += s.length();
55: }
56: }
57: }
58: return sb.toString();
59: }
60: }
|