Skip to content

Commit

Permalink
chore: extract email or mailing list name when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasCharrier authored Oct 2, 2024
1 parent 5d94594 commit e85f708
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions routes/mails.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ const Promise = require("bluebird");
const verification = require("../middlewares/slack");
const messages = require("../lib/messages");

// Helper function to extract mailing list name
function extractMailingListName(mailingList) {
if (mailingList.includes('@')) {

Check failure on line 11 in routes/mails.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Replace `'@'` with `"@"`
return mailingList.split('@')[0]; // Extracts the part before the '@'

Check failure on line 12 in routes/mails.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Replace `'@'` with `"@"`
}
return mailingList; // Returns the mailing list as is if it doesn't contain '@'
}

// Helper function to extract email address
function extractEmail(email) {
const match = email.match(/<([^>]+)>|([\w.-]+@[\w.-]+)/);
return match ? match[1] || match[2] : email; // Returns the extracted email or the original if not found
}

const helpMessage = `Commandes disponibles:
\t- \`/emails list\`\t\tensemble des listes de diffusions existantes
\t- \`/emails list id_de_la_liste\`\t\tpersonnes inscrites dans la liste email_de_la_liste@domain.com
Expand Down Expand Up @@ -65,7 +79,7 @@ function getSubscribers(mailingList) {
})
.catch(printAndReturnError);
}

mailingList = extractMailingListName(mailingList)

Check failure on line 82 in routes/mails.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Insert `;`
return ovh
.requestPromised(
"GET",
Expand Down Expand Up @@ -142,6 +156,7 @@ function help(res) {
function create(res, name, ownerEmail) {
let createPromise;
name = name.split("@")[0]; // if someone give the adress instead of the name
ownerEmail = extractEmail(ownerEmail)

Check failure on line 159 in routes/mails.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Insert `;`
// Subscribe from mailing-list
createPromise = ovh
.requestPromised("POST", `/email/domain/${config.domain}/mailingList`, {
Expand Down Expand Up @@ -183,6 +198,7 @@ function del(res, mailingList) {

function join(res, mailingList, email) {
let subscribePromise;
email = extractEmail(email);

const isSpecial = redirections.find((item) => item === mailingList);
if (isSpecial) {
Expand All @@ -199,6 +215,7 @@ function join(res, mailingList, email) {
.catch((err) => res.send(messages.error(err)));
} else {
// Subscribe from mailing-list
mailingList = extractMailingListName(mailingList)

Check failure on line 218 in routes/mails.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Insert `;`
subscribePromise = ovh
.requestPromised(
"POST",
Expand All @@ -217,7 +234,7 @@ function join(res, mailingList, email) {

function leave(res, mailingList, email) {
let leavePromise;

email = extractEmail(email);
if (redirections.indexOf(mailingList) >= 0) {
// Remove redirection
leavePromise = getRedirections(mailingList)
Expand Down

0 comments on commit e85f708

Please sign in to comment.