Merge pull request #2395 from philipwhiuk/jisSupportCheckstyle
Checkstyle fixed for JisSupport
This commit is contained in:
commit
89f3913cfa
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 String getJisVariantFromMessage(Message message) throws MessagingException {
|
||||
if (message == null)
|
||||
if (message == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// If a receiver is known to use a JIS variant, the sender transfers the message after converting the
|
||||
// charset as a convention.
|
||||
String variant = getJisVariantFromReceivedHeaders(message);
|
||||
if (variant != null)
|
||||
if (variant != null) {
|
||||
return variant;
|
||||
}
|
||||
|
||||
// If a receiver is not known to use any JIS variants, the sender transfers the message without converting
|
||||
// the charset.
|
||||
variant = getJisVariantFromFromHeaders(message);
|
||||
if (variant != null)
|
||||
if (variant != null) {
|
||||
return variant;
|
||||
}
|
||||
|
||||
return getJisVariantFromMailerHeaders(message);
|
||||
}
|
||||
|
@ -33,28 +36,32 @@ class JisSupport {
|
|||
}
|
||||
|
||||
public static String getJisVariantFromAddress(String address) {
|
||||
if (address == null)
|
||||
if (address == null) {
|
||||
return null;
|
||||
}
|
||||
if (isInDomain(address, "docomo.ne.jp") || isInDomain(address, "dwmail.jp") ||
|
||||
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";
|
||||
else if (isInDomain(address, "softbank.ne.jp") || isInDomain(address, "vodafone.ne.jp") ||
|
||||
isInDomain(address, "disney.ne.jp") || isInDomain(address, "vertuclub.ne.jp"))
|
||||
} else if (isInDomain(address, "softbank.ne.jp") || isInDomain(address, "vodafone.ne.jp") ||
|
||||
isInDomain(address, "disney.ne.jp") || isInDomain(address, "vertuclub.ne.jp")) {
|
||||
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 null;
|
||||
}
|
||||
|
||||
|
||||
private static String getJisVariantFromMailerHeaders(Message message) {
|
||||
String[] mailerHeaders = message.getHeader("X-Mailer");
|
||||
if (mailerHeaders.length == 0)
|
||||
if (mailerHeaders.length == 0) {
|
||||
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 null;
|
||||
}
|
||||
|
@ -62,16 +69,19 @@ class JisSupport {
|
|||
|
||||
private static String getJisVariantFromReceivedHeaders(Part message) throws MessagingException {
|
||||
String[] receivedHeaders = message.getHeader("Received");
|
||||
if (receivedHeaders.length == 0)
|
||||
if (receivedHeaders.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (String receivedHeader : receivedHeaders) {
|
||||
String address = getAddressFromReceivedHeader(receivedHeader);
|
||||
if (address == null)
|
||||
if (address == null) {
|
||||
continue;
|
||||
}
|
||||
String variant = getJisVariantFromAddress(address);
|
||||
if (variant != null)
|
||||
if (variant != null) {
|
||||
return variant;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -83,20 +93,23 @@ class JisSupport {
|
|||
|
||||
private static String getJisVariantFromFromHeaders(Message message) throws MessagingException {
|
||||
Address addresses[] = message.getFrom();
|
||||
if (addresses == null || addresses.length == 0)
|
||||
if (addresses == null || addresses.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getJisVariantFromAddress(addresses[0].getAddress());
|
||||
}
|
||||
|
||||
private static boolean isInDomain(String address, String domain) {
|
||||
int index = address.length() - domain.length() - 1;
|
||||
if (index < 0)
|
||||
if (index < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char c = address.charAt(index);
|
||||
if (c != '@' && c != '.')
|
||||
if (c != '@' && c != '.') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return address.endsWith(domain);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue