Skip to content

Commit

Permalink
#73: just improve readability slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
bbottema committed Apr 5, 2024
1 parent 3f79987 commit 1b789d8
Showing 1 changed file with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,32 @@ public void setProperty(final OutlookMessageProperty msgProp) {
properties.put(mapiClass, value);
}

private void handleNameAddressProperty(int mapiClass, String probablyNamePossiblyAddress) {
if (mapiClass == 0x3003 || mapiClass == 0x39fe) { // address
if ((this.address == null || nameWasUsedAsAddress) && probablyNamePossiblyAddress.contains("@")) {
setAddress(probablyNamePossiblyAddress);
nameWasUsedAsAddress = false;
} else if (this.address == null && probablyNamePossiblyAddress.matches("/o=[^/]+/ou=[^/]+(?:/cn=[^/]+)*")) {
// highly likely an X500 address
setAddress(probablyNamePossiblyAddress);
nameWasUsedAsAddress = false;
}
} else if (mapiClass == 0x3001) { // name
setName(probablyNamePossiblyAddress);
// If no name+email was given, Outlook will encode the value as name, even if it actually is an addres
// so just in that case, do a quick check to catch most use-cases where the name is actually the email address
if (this.address == null && probablyNamePossiblyAddress.contains("@")) {
setAddress(probablyNamePossiblyAddress);
nameWasUsedAsAddress = true;
}
private void handleNameAddressProperty(final int mapiClass, final String probablyNamePossiblyAddress) {
if (mapiClass == 0x3001) { // name
handleNameProperty(probablyNamePossiblyAddress);
} else if (mapiClass == 0x3003 || mapiClass == 0x39fe) { // address
handleAddressProperty(probablyNamePossiblyAddress);
}
}

private void handleNameProperty(final String probablyNamePossiblyAddress) {
setName(probablyNamePossiblyAddress);
// If no name+email was given, Outlook will encode the value as name, even if it actually is an addres
// so just in that case, do a quick check to catch most use-cases where the name is actually the email address
if (address == null && probablyNamePossiblyAddress.contains("@")) {
setAddress(probablyNamePossiblyAddress);
nameWasUsedAsAddress = true;
}
}

private void handleAddressProperty(final String probablyNamePossiblyAddress) {
if ((address == null || nameWasUsedAsAddress) && probablyNamePossiblyAddress.contains("@")) {
setAddress(probablyNamePossiblyAddress);
nameWasUsedAsAddress = false;
} else if (address == null && probablyNamePossiblyAddress.matches("/o=[^/]+/ou=[^/]+(?:/cn=[^/]+)*")) {
// highly likely an X500 address
setAddress(probablyNamePossiblyAddress);
nameWasUsedAsAddress = false;
}
}

Expand Down

0 comments on commit 1b789d8

Please sign in to comment.