From e110778a3f4c706a307e70ce7f4bd38a22a2e2bc Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 4 Jan 2022 00:28:49 +0100 Subject: Don't log trying to send a mail when mailer is disabled. --- server.js | 74 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/server.js b/server.js index e4b3802..ef65a73 100644 --- a/server.js +++ b/server.js @@ -1413,63 +1413,65 @@ function mail_describe(game) { } function mail_password_reset_token(user, token) { - let subject = "Password reset request"; - let body = - "Your password reset token is: " + token + "\n\n" + - SITE_URL + "/reset-password/" + user.mail + "/" + token + "\n\n" + - "If you did not request a password reset you can ignore this mail.\n"; if (mailer) { + let subject = "Password reset request"; + let body = + "Your password reset token is: " + token + "\n\n" + + SITE_URL + "/reset-password/" + user.mail + "/" + token + "\n\n" + + "If you did not request a password reset you can ignore this mail.\n"; console.log("SENT MAIL:", mail_addr(user), subject); mailer.sendMail({ from: MAIL_FROM, to: mail_addr(user), subject: subject, text: body }, mail_callback); - } else { - console.log("DID NOT SEND MAIL:", mail_addr(user), subject); } } function mail_new_message(user, msg_id, msg_from, msg_subject, msg_body) { - let subject = "You have a new message from " + msg_from + "."; - let body = "Subject: " + msg_subject + "\n\n" + - msg_body + "\n\n--\n" + - "You can reply to this message at:\n" + - SITE_URL + "/message/read/" + msg_id + "\n\n"; - console.log("SENT MAIL:", mail_addr(user), subject); - if (mailer) + if (mailer) { + let subject = "You have a new message from " + msg_from + "."; + let body = "Subject: " + msg_subject + "\n\n" + + msg_body + "\n\n--\n" + + "You can reply to this message at:\n" + + SITE_URL + "/message/read/" + msg_id + "\n\n"; + console.log("SENT MAIL:", mail_addr(user), subject); mailer.sendMail({ from: MAIL_FROM, to: mail_addr(user), subject: subject, text: body }, mail_callback); + } } function mail_your_turn_notification(user, game_id, interval) { - let too_soon = SQL_SELECT_NOTIFIED.get(interval, game_id, user.user_id); - if (!too_soon) { - SQL_INSERT_NOTIFIED.run(game_id, user.user_id); - let game = SQL_SELECT_GAME_FULL_VIEW.get(game_id); - let subject = game.title_name + " - " + game_id + " - Your turn!"; - let body = mail_describe(game) + - "It's your turn.\n\n" + - SITE_URL + "/play/" + game_id + "\n\n--\n" + - MAIL_FOOTER; - console.log("SENT MAIL:", mail_addr(user), subject); - if (mailer) + if (mailer) { + let too_soon = SQL_SELECT_NOTIFIED.get(interval, game_id, user.user_id); + if (!too_soon) { + SQL_INSERT_NOTIFIED.run(game_id, user.user_id); + let game = SQL_SELECT_GAME_FULL_VIEW.get(game_id); + let subject = game.title_name + " - " + game_id + " - Your turn!"; + let body = mail_describe(game) + + "It's your turn.\n\n" + + SITE_URL + "/play/" + game_id + "\n\n--\n" + + MAIL_FOOTER; + console.log("SENT MAIL:", mail_addr(user), subject); mailer.sendMail({ from: MAIL_FROM, to: mail_addr(user), subject: subject, text: body }, mail_callback); + } } } +} function reset_your_turn_notification(user, game_id) { SQL_DELETE_NOTIFIED.run(game_id, user.user_id); } function mail_ready_to_start_notification(user, game_id, interval) { - let too_soon = SQL_SELECT_NOTIFIED.get(interval, game_id, user.user_id); - if (!too_soon) { - SQL_INSERT_NOTIFIED.run(game_id, user.user_id); - let game = SQL_SELECT_GAME_FULL_VIEW.get(game_id); - let subject = game.title_name + " - " + game_id + " - Ready to start!"; - let body = mail_describe(game) + - "Your game is ready to start.\n\n" + - SITE_URL + "/join/" + game_id + "\n\n--\n" + - MAIL_FOOTER; - console.log("SENT MAIL:", mail_addr(user), subject); - if (mailer) + if (mailer) { + let too_soon = SQL_SELECT_NOTIFIED.get(interval, game_id, user.user_id); + if (!too_soon) { + SQL_INSERT_NOTIFIED.run(game_id, user.user_id); + let game = SQL_SELECT_GAME_FULL_VIEW.get(game_id); + let subject = game.title_name + " - " + game_id + " - Ready to start!"; + let body = mail_describe(game) + + "Your game is ready to start.\n\n" + + SITE_URL + "/join/" + game_id + "\n\n--\n" + + MAIL_FOOTER; + console.log("SENT MAIL:", mail_addr(user), subject); mailer.sendMail({ from: MAIL_FROM, to: mail_addr(user), subject: subject, text: body }, mail_callback); + } } } -- cgit v1.2.3