@Test public void testFold() throws Exception { Assert.assertEquals("this is\r\n a test", MimeUtil.fold("this is a test", 68)); Assert.assertEquals("this is\r\n a test", MimeUtil.fold("this is a test", 69)); Assert.assertEquals("this\r\n is a test", MimeUtil.fold("this is a test", 70)); Assert.assertEquals("this \r\n is a test", MimeUtil.fold( "this is a test", 70)); }
public static String fold(String s, int usedCharacters) { final int maxCharacters = 76; final int length = s.length(); if (usedCharacters + length <= maxCharacters) return s; StringBuilder sb = new StringBuilder(); int lastLineBreak = -usedCharacters; int wspIdx = indexOfWsp(s, 0); while (true) { if (wspIdx == length) { sb.append(s.substring(Math.max(0, lastLineBreak))); return sb.toString(); } int nextWspIdx = indexOfWsp(s, wspIdx + 1); if (nextWspIdx - lastLineBreak > maxCharacters) { sb.append(s.substring(Math.max(0, lastLineBreak), wspIdx)); sb.append("\r\n"); lastLineBreak = wspIdx; } wspIdx = nextWspIdx; } }
MimeUtil { public static String fold(String s, int usedCharacters) { final int maxCharacters = 76; final int length = s.length(); if (usedCharacters + length <= maxCharacters) return s; StringBuilder sb = new StringBuilder(); int lastLineBreak = -usedCharacters; int wspIdx = indexOfWsp(s, 0); while (true) { if (wspIdx == length) { sb.append(s.substring(Math.max(0, lastLineBreak))); return sb.toString(); } int nextWspIdx = indexOfWsp(s, wspIdx + 1); if (nextWspIdx - lastLineBreak > maxCharacters) { sb.append(s.substring(Math.max(0, lastLineBreak), wspIdx)); sb.append("\r\n"); lastLineBreak = wspIdx; } wspIdx = nextWspIdx; } } }
MimeUtil { public static String fold(String s, int usedCharacters) { final int maxCharacters = 76; final int length = s.length(); if (usedCharacters + length <= maxCharacters) return s; StringBuilder sb = new StringBuilder(); int lastLineBreak = -usedCharacters; int wspIdx = indexOfWsp(s, 0); while (true) { if (wspIdx == length) { sb.append(s.substring(Math.max(0, lastLineBreak))); return sb.toString(); } int nextWspIdx = indexOfWsp(s, wspIdx + 1); if (nextWspIdx - lastLineBreak > maxCharacters) { sb.append(s.substring(Math.max(0, lastLineBreak), wspIdx)); sb.append("\r\n"); lastLineBreak = wspIdx; } wspIdx = nextWspIdx; } } private  MimeUtil(); }
MimeUtil { public static String fold(String s, int usedCharacters) { final int maxCharacters = 76; final int length = s.length(); if (usedCharacters + length <= maxCharacters) return s; StringBuilder sb = new StringBuilder(); int lastLineBreak = -usedCharacters; int wspIdx = indexOfWsp(s, 0); while (true) { if (wspIdx == length) { sb.append(s.substring(Math.max(0, lastLineBreak))); return sb.toString(); } int nextWspIdx = indexOfWsp(s, wspIdx + 1); if (nextWspIdx - lastLineBreak > maxCharacters) { sb.append(s.substring(Math.max(0, lastLineBreak), wspIdx)); sb.append("\r\n"); lastLineBreak = wspIdx; } wspIdx = nextWspIdx; } } private  MimeUtil(); static boolean isSameMimeType(String pType1, String pType2); static boolean isMessage(String pMimeType); static boolean isMultipart(String pMimeType); static boolean isBase64Encoding(String pTransferEncoding); static boolean isQuotedPrintableEncoded(String pTransferEncoding); static String createUniqueBoundary(); static String createUniqueMessageId(String hostName); static String formatDate(Date date, TimeZone zone); static String fold(String s, int usedCharacters); static String unfold(String s); static String unscrambleHeaderValue(String headerValue); }
MimeUtil { public static String fold(String s, int usedCharacters) { final int maxCharacters = 76; final int length = s.length(); if (usedCharacters + length <= maxCharacters) return s; StringBuilder sb = new StringBuilder(); int lastLineBreak = -usedCharacters; int wspIdx = indexOfWsp(s, 0); while (true) { if (wspIdx == length) { sb.append(s.substring(Math.max(0, lastLineBreak))); return sb.toString(); } int nextWspIdx = indexOfWsp(s, wspIdx + 1); if (nextWspIdx - lastLineBreak > maxCharacters) { sb.append(s.substring(Math.max(0, lastLineBreak), wspIdx)); sb.append("\r\n"); lastLineBreak = wspIdx; } wspIdx = nextWspIdx; } } private  MimeUtil(); static boolean isSameMimeType(String pType1, String pType2); static boolean isMessage(String pMimeType); static boolean isMultipart(String pMimeType); static boolean isBase64Encoding(String pTransferEncoding); static boolean isQuotedPrintableEncoded(String pTransferEncoding); static String createUniqueBoundary(); static String createUniqueMessageId(String hostName); static String formatDate(Date date, TimeZone zone); static String fold(String s, int usedCharacters); static String unfold(String s); static String unscrambleHeaderValue(String headerValue); static final String ENC_QUOTED_PRINTABLE; static final String ENC_BINARY; static final String ENC_BASE64; static final String ENC_8BIT; static final String ENC_7BIT; }