Skip to content

Commit

Permalink
obfuscate item names in Amazon order emails
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenMassaro committed Dec 22, 2023
1 parent 8f39da0 commit 9286095
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Note that if the account you have specified in Bitwarden does not end in "gmail.

- `messageProcessingTimeoutSeconds` (default `60`): number of seconds that should be spent processing each individual message before cancelling attempt to obtain message
- `closeStoreWhenCacheExpires` (default `true`): whether the `close` method should be called on an IMAP store when it expires from the cache. This was added because it seems that particularly slow IMAP providers (like gmail, sometimes), get `FolderClosedExceptions` when a `close` call occurs concurrently with opening a new store.
- `obfuscateAmazonOrderSubject` (default `false`): if true, Amazon.com order emails will have the item name obfuscated. This is useful for us because we share an Amazon account and I do not want to accidentally see what items are ordered if they are a gift

## Steps to get Bitwarden IDs

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.massaro</groupId>
<artifactId>Email</artifactId>
<version>2.9.3</version>
<version>2.9.4</version>

<parent>
<groupId>org.springframework.boot</groupId>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/email/model/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.mail.util.MimeMessageParser;
import org.springframework.beans.factory.annotation.Value;

import javax.activation.DataSource;
import javax.mail.Flags;
Expand All @@ -27,6 +28,10 @@
@Log4j2
public class Message {

@JsonIgnore
@Value("${obfuscateAmazonOrderSubject:false}")
private boolean obfuscateAmazonOrderSubject;

private long id;
private long uid;
/**
Expand Down Expand Up @@ -87,6 +92,9 @@ public Message(javax.mail.Message message, long uid, boolean alreadyExists, Stri
this.fromAddress = sender.getAddress();
this.fromPersonal = sender.getPersonal();
}
if (obfuscateAmazonOrderSubject && this.fromAddress.equalsIgnoreCase("[email protected]")) {
this.subject = subject.replaceAll("\"(.*?)\"", "*****");
}
javax.mail.Address[] recipients = message.getRecipients(javax.mail.Message.RecipientType.TO);
if (ArrayUtils.isNotEmpty(recipients)) {
this.recipients = Arrays.stream(recipients).map(javax.mail.Address::toString).collect(Collectors.toList());
Expand Down

0 comments on commit 9286095

Please sign in to comment.