mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
WeKan only ever sent email; there was no way to receive it, so replying to a notification email went nowhere. This adds the webhook-based half of #2414 - not an IMAP-polling mail client, which would need a running mailbox, credentials and a polling loop the self-hoster would have to operate. Instead a self-hoster points a mail provider's inbound-parse webhook (Mailgun Routes, SendGrid Inbound Parse, Postmark inbound - documented in docs/Features/Email/Reply-By-Email.md) at a new POST /api/inbound-email. Every outbound notification email's Reply-To now carries reply+<cardId>-<hmac>@<domain> (server/lib/inboundEmailReplyToken.js), the HMAC keyed by INBOUND_EMAIL_HMAC_SECRET so it cannot be forged or guessed. The webhook verifies that token, resolves the card, strips the reply's quoted text (server/lib/inboundEmailQuoteStrip.js), matches the sender's address to an existing WeKan user (server/lib/inboundEmailUserMatch.js - no match is rejected, never an anonymous comment), and inserts a CardComments document. Unauthenticated by design, so every rejection (bad/forged token, unmatched sender) is logged via securityLog under the new authn.inbound-email catalog key, wrapped so logging can never break the guard. Both INBOUND_EMAIL_HMAC_SECRET and INBOUND_EMAIL_DOMAIN are opt-in; unset (the default), no Reply-To is added and existing installs are unchanged. Thanks to vasyugan and xet7 ! Closes #2414,
72 lines
2.7 KiB
JavaScript
72 lines
2.7 KiB
JavaScript
// emailLocalization.js
|
|
// Utility functions to handle email localization in Wekan
|
|
|
|
import { TAPi18n } from '/imports/i18n';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
|
|
// Main object for email localization utilities
|
|
const EmailLocalization = {
|
|
/**
|
|
* Send an email using the recipient's preferred language
|
|
* @param {Object} options - Standard email sending options plus language options
|
|
* @param {String} options.to - Recipient email address
|
|
* @param {String} options.from - Sender email address
|
|
* @param {String} options.subject - Email subject i18n key
|
|
* @param {String} options.text - Email text i18n key
|
|
* @param {Object} options.params - Parameters for i18n translation
|
|
* @param {String} options.language - Language code to use (if not provided, will try to detect)
|
|
* @param {String} options.userId - User ID to determine language (if not provided with language)
|
|
*/
|
|
async sendEmail(options) {
|
|
// Determine the language to use
|
|
let lang = options.language;
|
|
|
|
// If no language is specified but we have a userId, try to get the user's language
|
|
if (!lang && options.userId) {
|
|
const user = await ReactiveCache.getUser(options.userId);
|
|
if (user) {
|
|
lang = user.getLanguage();
|
|
}
|
|
}
|
|
|
|
// If no language could be determined, use the site default
|
|
if (!lang) {
|
|
lang = TAPi18n.getLanguage() || 'en';
|
|
}
|
|
|
|
// #5875: ensure the chosen language's bundle is loaded on the server before
|
|
// translating, otherwise __() falls back to English.
|
|
await TAPi18n.ensureLanguageLoaded(lang);
|
|
|
|
// Translate subject and text using the determined language
|
|
const subject = TAPi18n.__(options.subject, options.params || {}, lang);
|
|
let text = options.text;
|
|
|
|
// If text is an i18n key, translate it
|
|
if (typeof text === 'string' && text.startsWith('email-')) {
|
|
text = TAPi18n.__(text, options.params || {}, lang);
|
|
}
|
|
|
|
// Send the email with translated content
|
|
const mail = {
|
|
to: options.to,
|
|
from: options.from || Accounts.emailTemplates.from,
|
|
subject: subject,
|
|
text: text,
|
|
html: options.html
|
|
};
|
|
// #2414: reply-by-email - a Reply-To carrying an HMAC-signed card token,
|
|
// set by server/notifications/email.js, lets a reply sent through the
|
|
// inbound-email webhook (server/routes/inboundEmail.js) be matched back to
|
|
// the card it was about. Omitted entirely when the caller has none to give
|
|
// (e.g. WEKAN_INBOUND_EMAIL_DOMAIN is not configured).
|
|
if (options.replyTo) {
|
|
mail.replyTo = options.replyTo;
|
|
}
|
|
return await Email.sendAsync(mail);
|
|
}
|
|
};
|
|
|
|
// Add module.exports to make it accessible from other files
|
|
export default EmailLocalization;
|