@Test public void testGetHeaderParameter() { String result; result = MimeUtility.getHeaderParameter(";", null); assertEquals(null, result); result = MimeUtility.getHeaderParameter("name", "name"); assertEquals(null, result); result = MimeUtility.getHeaderParameter("name=", "name"); assertEquals("", result); result = MimeUtility.getHeaderParameter("name=\"", "name"); assertEquals("\"", result); result = MimeUtility.getHeaderParameter("name=value", "name"); assertEquals("value", result); result = MimeUtility.getHeaderParameter("name = value", "name"); assertEquals("value", result); result = MimeUtility.getHeaderParameter("name=\"value\"", "name"); assertEquals("value", result); result = MimeUtility.getHeaderParameter("name = \"value\"", "name"); assertEquals("value", result); result = MimeUtility.getHeaderParameter("name=\"\"", "name"); assertEquals("", result); result = MimeUtility.getHeaderParameter("text/html ; charset=\"windows-1251\"", null); assertEquals("text/html", result); result = MimeUtility.getHeaderParameter("text/HTML ; charset=\"windows-1251\"", null); assertEquals("text/HTML", result); }
public static String getHeaderParameter(String headerValue, String parameterName) { if (headerValue == null) { return null; } headerValue = headerValue.replaceAll("\r|\n", ""); String[] parts = headerValue.split(";"); if (parameterName == null && parts.length > 0) { return parts[0].trim(); } for (String part : parts) { if (parameterName != null && part.trim().toLowerCase(Locale.US).startsWith(parameterName.toLowerCase(Locale.US))) { String[] partParts = part.split("=", 2); if (partParts.length == 2) { String parameter = partParts[1].trim(); int len = parameter.length(); if (len >= 2 && parameter.startsWith("\"") && parameter.endsWith("\"")) { return parameter.substring(1, len - 1); } else { return parameter; } } } } return null; }
MimeUtility { public static String getHeaderParameter(String headerValue, String parameterName) { if (headerValue == null) { return null; } headerValue = headerValue.replaceAll("\r|\n", ""); String[] parts = headerValue.split(";"); if (parameterName == null && parts.length > 0) { return parts[0].trim(); } for (String part : parts) { if (parameterName != null && part.trim().toLowerCase(Locale.US).startsWith(parameterName.toLowerCase(Locale.US))) { String[] partParts = part.split("=", 2); if (partParts.length == 2) { String parameter = partParts[1].trim(); int len = parameter.length(); if (len >= 2 && parameter.startsWith("\"") && parameter.endsWith("\"")) { return parameter.substring(1, len - 1); } else { return parameter; } } } } return null; } }
MimeUtility { public static String getHeaderParameter(String headerValue, String parameterName) { if (headerValue == null) { return null; } headerValue = headerValue.replaceAll("\r|\n", ""); String[] parts = headerValue.split(";"); if (parameterName == null && parts.length > 0) { return parts[0].trim(); } for (String part : parts) { if (parameterName != null && part.trim().toLowerCase(Locale.US).startsWith(parameterName.toLowerCase(Locale.US))) { String[] partParts = part.split("=", 2); if (partParts.length == 2) { String parameter = partParts[1].trim(); int len = parameter.length(); if (len >= 2 && parameter.startsWith("\"") && parameter.endsWith("\"")) { return parameter.substring(1, len - 1); } else { return parameter; } } } } return null; }  }
MimeUtility { public static String getHeaderParameter(String headerValue, String parameterName) { if (headerValue == null) { return null; } headerValue = headerValue.replaceAll("\r|\n", ""); String[] parts = headerValue.split(";"); if (parameterName == null && parts.length > 0) { return parts[0].trim(); } for (String part : parts) { if (parameterName != null && part.trim().toLowerCase(Locale.US).startsWith(parameterName.toLowerCase(Locale.US))) { String[] partParts = part.split("=", 2); if (partParts.length == 2) { String parameter = partParts[1].trim(); int len = parameter.length(); if (len >= 2 && parameter.startsWith("\"") && parameter.endsWith("\"")) { return parameter.substring(1, len - 1); } else { return parameter; } } } } return null; }  static String unfold(String s); static String unfoldAndDecode(String s); static String unfoldAndDecode(String s, Message message); static String foldAndEncode(String s); static String getHeaderParameter(String headerValue, String parameterName); static Map<String,String> getAllHeaderParameters(String headerValue); static Part findFirstPartByMimeType(Part part, String mimeType); static boolean mimeTypeMatches(String mimeType, String matchAgainst); static boolean isDefaultMimeType(String mimeType); static InputStream decodeBody(Body body); static void closeInputStreamWithoutDeletingTemporaryFiles(InputStream rawInputStream); static String getMimeTypeByExtension(String filename); static String getExtensionByMimeType(@NonNull String mimeType); static String getEncodingforType(String type); static boolean isMultipart(String mimeType); static boolean isMessage(String mimeType); static boolean isSameMimeType(String mimeType, String otherMimeType); }
MimeUtility { public static String getHeaderParameter(String headerValue, String parameterName) { if (headerValue == null) { return null; } headerValue = headerValue.replaceAll("\r|\n", ""); String[] parts = headerValue.split(";"); if (parameterName == null && parts.length > 0) { return parts[0].trim(); } for (String part : parts) { if (parameterName != null && part.trim().toLowerCase(Locale.US).startsWith(parameterName.toLowerCase(Locale.US))) { String[] partParts = part.split("=", 2); if (partParts.length == 2) { String parameter = partParts[1].trim(); int len = parameter.length(); if (len >= 2 && parameter.startsWith("\"") && parameter.endsWith("\"")) { return parameter.substring(1, len - 1); } else { return parameter; } } } } return null; }  static String unfold(String s); static String unfoldAndDecode(String s); static String unfoldAndDecode(String s, Message message); static String foldAndEncode(String s); static String getHeaderParameter(String headerValue, String parameterName); static Map<String,String> getAllHeaderParameters(String headerValue); static Part findFirstPartByMimeType(Part part, String mimeType); static boolean mimeTypeMatches(String mimeType, String matchAgainst); static boolean isDefaultMimeType(String mimeType); static InputStream decodeBody(Body body); static void closeInputStreamWithoutDeletingTemporaryFiles(InputStream rawInputStream); static String getMimeTypeByExtension(String filename); static String getExtensionByMimeType(@NonNull String mimeType); static String getEncodingforType(String type); static boolean isMultipart(String mimeType); static boolean isMessage(String mimeType); static boolean isSameMimeType(String mimeType, String otherMimeType); static final String DEFAULT_ATTACHMENT_MIME_TYPE; static final String K9_SETTINGS_MIME_TYPE; }