1 16 package org.apache.commons.net.smtp; 17 18 47 48 public class SimpleSMTPHeader 49 { 50 private String __subject, __from, __to; 51 private StringBuffer __headerFields, __cc; 52 53 64 public SimpleSMTPHeader(String from, String to, String subject) 65 { 66 __to = to; 67 __from = from; 68 __subject = subject; 69 __headerFields = new StringBuffer (); 70 __cc = null; 71 } 72 73 85 public void addHeaderField(String headerField, String value) 86 { 87 __headerFields.append(headerField); 88 __headerFields.append(": "); 89 __headerFields.append(value); 90 __headerFields.append('\n'); 91 } 92 93 94 99 public void addCC(String address) 100 { 101 if (__cc == null) 102 __cc = new StringBuffer (); 103 else 104 __cc.append(", "); 105 106 __cc.append(address); 107 } 108 109 110 118 public String toString() 119 { 120 StringBuffer header = new StringBuffer (); 121 122 if (__headerFields.length() > 0) 123 header.append(__headerFields.toString()); 124 125 header.append("From: "); 126 header.append(__from); 127 header.append("\nTo: "); 128 header.append(__to); 129 130 if (__cc != null) 131 { 132 header.append("\nCc: "); 133 header.append(__cc.toString()); 134 } 135 136 if (__subject != null) 137 { 138 header.append("\nSubject: "); 139 header.append(__subject); 140 } 141 142 header.append('\n'); 143 header.append('\n'); 144 145 return header.toString(); 146 } 147 } 148 149 150 151 | Popular Tags |