4646 */
4747abstract class RFC1522Codec {
4848
49+ /**
50+ * Separator.
51+ */
52+ protected static final char SEP = '?' ;
53+
54+ /**
55+ * Prefix
56+ */
57+ protected static final String POSTFIX = "?=" ;
58+
59+ /**
60+ * Postfix
61+ */
62+ protected static final String PREFIX = "=?" ;
63+
4964 /**
5065 * Applies an RFC 1522 compliant encoding scheme to the given string of text with the
5166 * given charset. This method constructs the "encoded-word" header common to all the
@@ -70,14 +85,14 @@ protected String encodeText(final String text, final String charset)
7085 return null ;
7186 }
7287 StringBuffer buffer = new StringBuffer ();
73- buffer .append ("=?" );
74- buffer .append (charset );
75- buffer .append ('?' );
76- buffer .append (getEncoding ());
77- buffer .append ('?' );
88+ buffer .append (PREFIX );
89+ buffer .append (charset );
90+ buffer .append (SEP );
91+ buffer .append (getEncoding ());
92+ buffer .append (SEP );
7893 byte [] rawdata = doEncoding (text .getBytes (charset ));
7994 buffer .append (StringUtils .newStringUsAscii (rawdata ));
80- buffer .append ("?=" );
95+ buffer .append (POSTFIX );
8196 return buffer .toString ();
8297 }
8398
@@ -100,12 +115,12 @@ protected String decodeText(final String text)
100115 if (text == null ) {
101116 return null ;
102117 }
103- if ((!text .startsWith ("=?" )) || (!text .endsWith ("?=" ))) {
118+ if ((!text .startsWith (PREFIX )) || (!text .endsWith (POSTFIX ))) {
104119 throw new DecoderException ("RFC 1522 violation: malformed encoded content" );
105120 }
106121 int termnator = text .length () - 2 ;
107122 int from = 2 ;
108- int to = text .indexOf ("?" , from );
123+ int to = text .indexOf (SEP , from );
109124 if ((to == -1 ) || (to == termnator )) {
110125 throw new DecoderException ("RFC 1522 violation: charset token not found" );
111126 }
@@ -114,7 +129,7 @@ protected String decodeText(final String text)
114129 throw new DecoderException ("RFC 1522 violation: charset not specified" );
115130 }
116131 from = to + 1 ;
117- to = text .indexOf ("?" , from );
132+ to = text .indexOf (SEP , from );
118133 if ((to == -1 ) || (to == termnator )) {
119134 throw new DecoderException ("RFC 1522 violation: encoding token not found" );
120135 }
@@ -124,7 +139,7 @@ protected String decodeText(final String text)
124139 encoding + " encoded content" );
125140 }
126141 from = to + 1 ;
127- to = text .indexOf ("?" , from );
142+ to = text .indexOf (SEP , from );
128143 byte [] data = StringUtils .getBytesUsAscii (text .substring (from , to ));
129144 data = doDecoding (data );
130145 return new String (data , charset );
0 commit comments