Class EMailNotifier
java.lang.Object
page.codeberg.friedolyn.notifications.Notifier
page.codeberg.friedolyn.notifications.EMailNotifier
- All Implemented Interfaces:
Copyable<EMailNotifier>,Redactable
A
Notifier that sends e-mail notifications via the university's
SMTP
server. In order to send e-mails, the user's university e-mail address is needed. In order to be notified of
incoming e-mails, the user must have set up an e-mail client that regularly checks the inbox. The following e-mail
clients are particularly recommended:
- Mozilla Thunderbird (all desktop platforms)
- GNOME Evolution (Linux)
- K-9 Mail (Android)
-
Nested Class Summary
Nested classes/interfaces inherited from class page.codeberg.friedolyn.notifications.Notifier
Notifier.Mood -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate @NonNull ConfigurationThe student's settings, including the e-mail address and password (both must be set) that will be used to authenticate with the university's SMTP server.private @NonNull EMailSenderUsed to actually submit notifications via SMTP.private booleanWhether e-mail notifications should be encrypted with PGP, using the student's public key as specified inconfiguration.getContactMethods().getPgpPublicKey(). -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateEMailNotifier(boolean enablePgpEncryption) Deprecated.This constructor is only for Jackson to (de-)serialize this class.EMailNotifier(@NonNull Configuration configuration) EMailNotifier(@NonNull Configuration configuration, boolean enablePgpEncryption) -
Method Summary
Modifier and TypeMethodDescription@NonNull EMailNotifiercopy()booleanCompares thisEMailNotifierwith the givenObject.@NonNull Configurationboolean@NonNull ConfigurationvoidsendNotification(@NonNull String subject, @NonNull String summary, @NonNull String message, File attachment, @NonNull Notifier.Mood mood) voidsendNotification(@NonNull String subject, @NonNull String summary, @NonNull String message, @NonNull Notifier.Mood mood) Sends an e-mail to the user, notifying them about the given subject, summary and message, but without any attachment.@NonNull StringtoString()@NonNull StringMethods inherited from class page.codeberg.friedolyn.notifications.Notifier
sendNotification
-
Field Details
-
configuration
The student's settings, including the e-mail address and password (both must be set) that will be used to authenticate with the university's SMTP server. -
encryptMailWithPGP
private boolean encryptMailWithPGPWhether e-mail notifications should be encrypted with PGP, using the student's public key as specified inconfiguration.getContactMethods().getPgpPublicKey(). -
eMailSender
Used to actually submit notifications via SMTP.
-
-
Constructor Details
-
EMailNotifier
@Deprecated private EMailNotifier(boolean enablePgpEncryption) throws jakarta.mail.internet.AddressException Deprecated.This constructor is only for Jackson to (de-)serialize this class.- Parameters:
enablePgpEncryption- SeeencryptMailWithPGP.- Throws:
jakarta.mail.internet.AddressException- Never thrown in practice.
-
EMailNotifier
- Parameters:
configuration- The student's settings, including the e-mail address and password (both must be set) that will be used to authenticate with the university's SMTP server. The exact reference to the object will be used instead of a deep copy.- Throws:
IllegalArgumentException- If the password is null or empty.
-
EMailNotifier
public EMailNotifier(@NonNull @NonNull Configuration configuration, boolean enablePgpEncryption) throws IllegalArgumentException - Parameters:
configuration- The student's settings, including the e-mail address and password (both must be set) that will be used to authenticate with the university's SMTP server. The exact reference to the object will be used instead of a deep copy.enablePgpEncryption- Whether e-mail notifications should be encrypted with PGP, using the student's public key as specified inconfiguration.getContactMethods().getPgpPublicKey(). If no public key is set, e-mail notifications will not be encrypted.- Throws:
IllegalArgumentException- If the password is null or empty.
-
-
Method Details
-
sendNotification
public void sendNotification(@NonNull @NonNull String subject, @NonNull @NonNull String summary, @NonNull @NonNull String message, @NonNull @NonNull Notifier.Mood mood) throws RuntimeException Sends an e-mail to the user, notifying them about the given subject, summary and message, but without any attachment.- Specified by:
sendNotificationin classNotifier- Parameters:
subject- What the notification is about.summary- Will be ignored.message- The full text of the e-mail that should be sent to the user.mood- Whether the content of the message contains news that the user will likely perceive as positive, or negative (or neither – in which case the mood is neutral).- Throws:
RuntimeException- If the notification could not be sent or if the subject or message is blank.- See Also:
-
sendNotification
public void sendNotification(@NonNull @NonNull String subject, @NonNull @NonNull String summary, @NonNull @NonNull String message, File attachment, @NonNull @NonNull Notifier.Mood mood) throws RuntimeException Sends an e-mail to the user, notifying them about the given subject, summary and message, with the given file attached.- Parameters:
subject- What the notification is about.summary- Will be ignored.message- The full text of the e-mail that should be sent to the user.attachment- The file that should be attached to the e-mail. Will be ignored if null.mood- Whether the content of the message contains news that the user will likely perceive as positive, or negative (or neither – in which case the mood is neutral).- Throws:
RuntimeException- If the notification could not be sent or if the subject or message is blank.
-
getEncryptMailWithPGP
public boolean getEncryptMailWithPGP()- Returns:
- Whether e-mail notifications should be
encrypted with
PGP, using the student's public key as
specified in
configuration.getContactMethods().getPgpPublicKey().
-
getConfiguration
- Returns:
- A deep copy of the
configurationthat provides the student's SMTP credentials inconfiguration.getEmail()andconfiguration.getPassword().
-
getReferenceToConfiguration
- Returns:
- The exact reference to the
configurationthat provides the student's SMTP credentials inconfiguration.getEmail()andconfiguration.getPassword().
-
toString
- Specified by:
toStringin interfaceRedactable- Specified by:
toStringin classNotifier- Returns:
- A string representation of this object including all fields, even sensitive ones.
-
toStringRedacted
- Specified by:
toStringRedactedin interfaceRedactable- Specified by:
toStringRedactedin classNotifier- Returns:
- A string representation of this object including all fields. However, sensitive fields will be removed or replaced with a placeholder. The exact behaviour is implementation-specific and may depend on the debug level currently in effect.
-
copy
- Specified by:
copyin interfaceCopyable<EMailNotifier>- Returns:
- A deep copy of the object, i.e. a clone that has the exact same values as the original object, but is a different instance (new reference).
-
equals
Compares thisEMailNotifierwith the givenObject.- Overrides:
equalsin classObject- Parameters:
object- TheObjectto compare thisEMailNotifierwith.- Returns:
-
trueif the given object is anEMailNotifierwhose fields' values match their equivalents in thisEMailNotifier, especially (but not exclusively) if the givenEMailNotifieris the exact same reference as thisEMailNotifier. -
falseif the given object is not aEMailNotifieror if any of the fields' values differ from their equivalents in thisEMailNotifier.
-
-