KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > mail > MailUtilities


1 /*
2  * MailUtilities.java
3  *
4  * Copyright (C) 2000-2003 Peter Graves
5  * $Id: MailUtilities.java,v 1.2 2003/03/09 14:01:01 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * 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 JavaDoc;
25 import org.armedbear.j.FastStringBuffer;
26 import org.armedbear.j.Utilities;
27
28 public class MailUtilities
29 {
30     public static String JavaDoc constructAddressHeader(String JavaDoc prefix, List JavaDoc list)
31     {
32         return constructAddressHeader(prefix, list, 8);
33     }
34
35     public static String JavaDoc constructAddressHeader(String JavaDoc prefix, List JavaDoc list,
36         int indent)
37     {
38         FastStringBuffer sb = new FastStringBuffer(prefix);
39         int length = prefix.length();
40         if (list != null) {
41             for (int i = 0; i < list.size(); i++) {
42                 MailAddress a = (MailAddress) list.get(i);
43                 String JavaDoc s = a.toEncodedString();
44                 if (i > 0 && length + s.length() > 74) {
45                     // Won't fit on current line.
46
sb.append(',');
47                     sb.append('\n');
48                     sb.append(Utilities.spaces(indent)); // Continuation.
49
sb.append(s);
50                     length = indent + s.length();
51                 } else {
52                     if (i > 0) {
53                         sb.append(", ");
54                         length += 2;
55                     }
56                     sb.append(s);
57                     length += s.length();
58                 }
59             }
60         }
61         return sb.toString();
62     }
63 }
64
Popular Tags