Checkstyle fixed for JisSupport
This commit is contained in:
parent
e590efaf8e
commit
309b6891f4
1 changed files with 29 additions and 16 deletions
|
@ -9,20 +9,23 @@ class JisSupport {
|
||||||
public static final String SHIFT_JIS = "shift_jis";
|
public static final String SHIFT_JIS = "shift_jis";
|
||||||
|
|
||||||
public static String getJisVariantFromMessage(Message message) throws MessagingException {
|
public static String getJisVariantFromMessage(Message message) throws MessagingException {
|
||||||
if (message == null)
|
if (message == null) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// If a receiver is known to use a JIS variant, the sender transfers the message after converting the
|
// If a receiver is known to use a JIS variant, the sender transfers the message after converting the
|
||||||
// charset as a convention.
|
// charset as a convention.
|
||||||
String variant = getJisVariantFromReceivedHeaders(message);
|
String variant = getJisVariantFromReceivedHeaders(message);
|
||||||
if (variant != null)
|
if (variant != null) {
|
||||||
return variant;
|
return variant;
|
||||||
|
}
|
||||||
|
|
||||||
// If a receiver is not known to use any JIS variants, the sender transfers the message without converting
|
// If a receiver is not known to use any JIS variants, the sender transfers the message without converting
|
||||||
// the charset.
|
// the charset.
|
||||||
variant = getJisVariantFromFromHeaders(message);
|
variant = getJisVariantFromFromHeaders(message);
|
||||||
if (variant != null)
|
if (variant != null) {
|
||||||
return variant;
|
return variant;
|
||||||
|
}
|
||||||
|
|
||||||
return getJisVariantFromMailerHeaders(message);
|
return getJisVariantFromMailerHeaders(message);
|
||||||
}
|
}
|
||||||
|
@ -33,28 +36,32 @@ class JisSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getJisVariantFromAddress(String address) {
|
public static String getJisVariantFromAddress(String address) {
|
||||||
if (address == null)
|
if (address == null) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
if (isInDomain(address, "docomo.ne.jp") || isInDomain(address, "dwmail.jp") ||
|
if (isInDomain(address, "docomo.ne.jp") || isInDomain(address, "dwmail.jp") ||
|
||||||
isInDomain(address, "pdx.ne.jp") || isInDomain(address, "willcom.com") ||
|
isInDomain(address, "pdx.ne.jp") || isInDomain(address, "willcom.com") ||
|
||||||
isInDomain(address, "emnet.ne.jp") || isInDomain(address, "emobile.ne.jp"))
|
isInDomain(address, "emnet.ne.jp") || isInDomain(address, "emobile.ne.jp")) {
|
||||||
return "docomo";
|
return "docomo";
|
||||||
else if (isInDomain(address, "softbank.ne.jp") || isInDomain(address, "vodafone.ne.jp") ||
|
} else if (isInDomain(address, "softbank.ne.jp") || isInDomain(address, "vodafone.ne.jp") ||
|
||||||
isInDomain(address, "disney.ne.jp") || isInDomain(address, "vertuclub.ne.jp"))
|
isInDomain(address, "disney.ne.jp") || isInDomain(address, "vertuclub.ne.jp")) {
|
||||||
return "softbank";
|
return "softbank";
|
||||||
else if (isInDomain(address, "ezweb.ne.jp") || isInDomain(address, "ido.ne.jp"))
|
} else if (isInDomain(address, "ezweb.ne.jp") || isInDomain(address, "ido.ne.jp")) {
|
||||||
return "kddi";
|
return "kddi";
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String getJisVariantFromMailerHeaders(Message message) {
|
private static String getJisVariantFromMailerHeaders(Message message) {
|
||||||
String[] mailerHeaders = message.getHeader("X-Mailer");
|
String[] mailerHeaders = message.getHeader("X-Mailer");
|
||||||
if (mailerHeaders.length == 0)
|
if (mailerHeaders.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (mailerHeaders[0].startsWith("iPhone Mail ") || mailerHeaders[0].startsWith("iPad Mail "))
|
if (mailerHeaders[0].startsWith("iPhone Mail ") || mailerHeaders[0].startsWith("iPad Mail ")) {
|
||||||
return "iphone";
|
return "iphone";
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -62,16 +69,19 @@ class JisSupport {
|
||||||
|
|
||||||
private static String getJisVariantFromReceivedHeaders(Part message) throws MessagingException {
|
private static String getJisVariantFromReceivedHeaders(Part message) throws MessagingException {
|
||||||
String[] receivedHeaders = message.getHeader("Received");
|
String[] receivedHeaders = message.getHeader("Received");
|
||||||
if (receivedHeaders.length == 0)
|
if (receivedHeaders.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
for (String receivedHeader : receivedHeaders) {
|
for (String receivedHeader : receivedHeaders) {
|
||||||
String address = getAddressFromReceivedHeader(receivedHeader);
|
String address = getAddressFromReceivedHeader(receivedHeader);
|
||||||
if (address == null)
|
if (address == null) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
String variant = getJisVariantFromAddress(address);
|
String variant = getJisVariantFromAddress(address);
|
||||||
if (variant != null)
|
if (variant != null) {
|
||||||
return variant;
|
return variant;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -83,20 +93,23 @@ class JisSupport {
|
||||||
|
|
||||||
private static String getJisVariantFromFromHeaders(Message message) throws MessagingException {
|
private static String getJisVariantFromFromHeaders(Message message) throws MessagingException {
|
||||||
Address addresses[] = message.getFrom();
|
Address addresses[] = message.getFrom();
|
||||||
if (addresses == null || addresses.length == 0)
|
if (addresses == null || addresses.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return getJisVariantFromAddress(addresses[0].getAddress());
|
return getJisVariantFromAddress(addresses[0].getAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isInDomain(String address, String domain) {
|
private static boolean isInDomain(String address, String domain) {
|
||||||
int index = address.length() - domain.length() - 1;
|
int index = address.length() - domain.length() - 1;
|
||||||
if (index < 0)
|
if (index < 0) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
char c = address.charAt(index);
|
char c = address.charAt(index);
|
||||||
if (c != '@' && c != '.')
|
if (c != '@' && c != '.') {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return address.endsWith(domain);
|
return address.endsWith(domain);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue