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 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.private @NonNull EMailSender
Used to actually submit notifications via SMTP.private boolean
Whether e-mail notifications should be encrypted with PGP, using the student's public key as specified inconfiguration.getContactMethods().getPgpPublicKey()
. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
EMailNotifier
(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 EMailNotifier
copy()
boolean
Compares thisEMailNotifier
with the givenObject
.@NonNull Configuration
boolean
@NonNull Configuration
void
sendNotification
(@NonNull String subject, @NonNull String summary, @NonNull String message, File attachment, @NonNull Notifier.Mood mood) void
sendNotification
(@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 String
toString()
@NonNull String
Methods 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:
sendNotification
in 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
configuration
that provides the student's SMTP credentials inconfiguration.getEmail()
andconfiguration.getPassword()
.
-
getReferenceToConfiguration
- Returns:
- The exact reference to the
configuration
that provides the student's SMTP credentials inconfiguration.getEmail()
andconfiguration.getPassword()
.
-
toString
- Specified by:
toString
in interfaceRedactable
- Specified by:
toString
in classNotifier
- Returns:
- A string representation of this object including all fields, even sensitive ones.
-
toStringRedacted
- Specified by:
toStringRedacted
in interfaceRedactable
- Specified by:
toStringRedacted
in 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:
copy
in 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 thisEMailNotifier
with the givenObject
.- Overrides:
equals
in classObject
- Parameters:
object
- TheObject
to compare thisEMailNotifier
with.- Returns:
-
true
if the given object is anEMailNotifier
whose fields' values match their equivalents in thisEMailNotifier
, especially (but not exclusively) if the givenEMailNotifier
is the exact same reference as thisEMailNotifier
. -
false
if the given object is not aEMailNotifier
or if any of the fields' values differ from their equivalents in thisEMailNotifier
.
-
-