Add author name, dates, threading to emails to the mailing list
This commit is contained in:
parent
8f8d995e69
commit
409b40cffb
2 changed files with 27 additions and 14 deletions
|
|
@ -542,7 +542,7 @@ proc reply(c: var TForumData): bool =
|
||||||
exec(db, sql"update thread set modified = DATETIME('now') where id = ?",
|
exec(db, sql"update thread set modified = DATETIME('now') where id = ?",
|
||||||
$c.threadId)
|
$c.threadId)
|
||||||
asyncCheck sendMailToMailingList(c.config, c.username, c.email,
|
asyncCheck sendMailToMailingList(c.config, c.username, c.email,
|
||||||
subject, content)
|
subject, content, threadId=c.threadId, postId=c.postID, is_reply=true)
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
proc newThread(c: var TForumData): bool =
|
proc newThread(c: var TForumData): bool =
|
||||||
|
|
@ -562,7 +562,7 @@ proc newThread(c: var TForumData): bool =
|
||||||
discard tryExec(db, sql"insert into post_fts(post_fts) values('optimize')")
|
discard tryExec(db, sql"insert into post_fts(post_fts) values('optimize')")
|
||||||
discard tryExec(db, sql"insert into post_fts(thread_fts) values('optimize')")
|
discard tryExec(db, sql"insert into post_fts(thread_fts) values('optimize')")
|
||||||
asyncCheck sendMailToMailingList(c.config, c.username, c.email,
|
asyncCheck sendMailToMailingList(c.config, c.username, c.email,
|
||||||
subject, content)
|
subject, content, threadId=c.threadID, postId=c.postID, is_reply=false)
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
proc login(c: var TForumData, name, pass: string): bool =
|
proc login(c: var TForumData, name, pass: string): bool =
|
||||||
|
|
|
||||||
37
utils.nim
37
utils.nim
|
|
@ -1,4 +1,5 @@
|
||||||
import asyncdispatch, smtp, strutils, json, os
|
import asyncdispatch, smtp, strutils, json, os
|
||||||
|
from times import getTime, getGMTime, format
|
||||||
|
|
||||||
type
|
type
|
||||||
Config* = object
|
Config* = object
|
||||||
|
|
@ -21,7 +22,7 @@ proc loadConfig*(filename = getCurrentDir() / "forum.json"): Config =
|
||||||
except:
|
except:
|
||||||
echo("[WARNING] Couldn't read config file: ./forum.json")
|
echo("[WARNING] Couldn't read config file: ./forum.json")
|
||||||
|
|
||||||
proc sendMail(config: Config, subject, message, recipient: string, from_addr = "forum@nim-lang.org", resent_from = "") {.async.} =
|
proc sendMail(config: Config, subject, message, recipient: string, from_addr = "forum@nim-lang.org", otherHeaders:seq[(string, string)] = @[]) {.async.} =
|
||||||
var client = newAsyncSmtp(config.smtpAddress, Port(config.smtpPort))
|
var client = newAsyncSmtp(config.smtpAddress, Port(config.smtpPort))
|
||||||
await client.connect()
|
await client.connect()
|
||||||
if config.smtpUser.len > 0:
|
if config.smtpUser.len > 0:
|
||||||
|
|
@ -29,24 +30,36 @@ proc sendMail(config: Config, subject, message, recipient: string, from_addr = "
|
||||||
|
|
||||||
let toList = @[recipient]
|
let toList = @[recipient]
|
||||||
|
|
||||||
let otherHeaders =
|
|
||||||
if resent_from == "":
|
|
||||||
@[]
|
|
||||||
else:
|
|
||||||
@[("Resent-From", resent_from)]
|
|
||||||
|
|
||||||
let encoded = createMessage(subject, message,
|
let encoded = createMessage(subject, message,
|
||||||
toList, @[], otherHeaders)
|
toList, @[], otherHeaders)
|
||||||
|
|
||||||
await client.sendMail(from_addr, toList,
|
await client.sendMail(from_addr, toList, $encoded)
|
||||||
$encoded)
|
|
||||||
|
|
||||||
proc sendMailToMailingList*(config: Config, username, user_email_addr, subject, message: string) {.async.} =
|
proc sendMailToMailingList*(config: Config, username, user_email_addr, subject, message: string, thread_id=0, post_id=0, is_reply=false) {.async.} =
|
||||||
# send message to a mailing list
|
# send message to a mailing list
|
||||||
|
if config.mlistAddress == "":
|
||||||
|
return
|
||||||
|
|
||||||
let from_addr = "$# <$#>" % [username, user_email_addr]
|
let from_addr = "$# <$#>" % [username, user_email_addr]
|
||||||
|
|
||||||
if config.mlistAddress != "":
|
let date = getTime().getGMTime().format("ddd, d MMM yyyy HH:mm:ss") & " +0000"
|
||||||
await sendMail(config, subject, message, config.mlistAddress, from_addr=from_addr, resent_from="forum@nim-lang.org")
|
var otherHeaders = @[
|
||||||
|
("Date", date),
|
||||||
|
("Resent-From", "forum@nim-lang.org"),
|
||||||
|
("Resent-date", date)
|
||||||
|
]
|
||||||
|
|
||||||
|
if is_reply:
|
||||||
|
let msg_id = "<forum-id-$#-$#@nim-lang.org>" % [$thread_id, $post_id]
|
||||||
|
otherHeaders.add(("Message-ID", msg_id))
|
||||||
|
let references = "<forum-tid-$#@nim-lang.org>" % [$thread_id]
|
||||||
|
otherHeaders.add(("References", references))
|
||||||
|
|
||||||
|
else: # New thread
|
||||||
|
let msg_id = "<forum-tid-$#@nim-lang.org>" % $thread_id
|
||||||
|
otherHeaders.add(("Message-ID", msg_id))
|
||||||
|
|
||||||
|
await sendMail(config, subject, message, config.mlistAddress, from_addr=from_addr, otherHeaders=otherHeaders)
|
||||||
|
|
||||||
proc sendPassReset*(config: Config, email, user, resetUrl: string) {.async.} =
|
proc sendPassReset*(config: Config, email, user, resetUrl: string) {.async.} =
|
||||||
let message = """Hello $1,
|
let message = """Hello $1,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue