Mercurial > prosody-modules
annotate mod_email/mod_email.lua @ 5418:f2c7bb3af600
mod_http_oauth2: Add role selector to consent page
List includes all roles available to the user, if more than one.
Defaults to either the first role in the scope string or the users
primary role.
Earlier draft listed all roles, but having options that can't be
selected is bad UX and the entire list of all roles on the server could
be long, and perhaps even sensitive.
Allows e.g. picking a role with fewer permissions than what might
otherwise have been selected.
UX wise, doing this with more checkboxes or possibly radio buttons would
have been confusion and/or looked messier.
Fixes the previous situation where unselecting a role would default to
the primary role, which could be more permissions than requested.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 05 May 2023 01:23:13 +0200 |
parents | 070faeaf51bc |
children |
rev | line source |
---|---|
3762
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 module:set_global(); |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local moduleapi = require "core.moduleapi"; |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local smtp = require"socket.smtp"; |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local config = module:get_option("smtp", { origin = "prosody", exec = "sendmail" }); |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local function send_email(to, headers, content) |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 if type(headers) == "string" then -- subject |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 headers = { |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 Subject = headers; |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 From = config.origin; |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 }; |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 end |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 headers.To = to; |
3836
070faeaf51bc
mod_email: Allow sender to override content-type
Matthew Wild <mwild1@gmail.com>
parents:
3762
diff
changeset
|
17 if not headers["Content-Type"] then |
070faeaf51bc
mod_email: Allow sender to override content-type
Matthew Wild <mwild1@gmail.com>
parents:
3762
diff
changeset
|
18 headers["Content-Type"] = 'text/plain; charset="utf-8"'; |
070faeaf51bc
mod_email: Allow sender to override content-type
Matthew Wild <mwild1@gmail.com>
parents:
3762
diff
changeset
|
19 end |
3762
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local message = smtp.message{ |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 headers = headers; |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 body = content; |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 }; |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 if config.exec then |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 local pipe = io.popen(config.exec .. |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 " '"..to:gsub("'", "'\\''").."'", "w"); |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 for str in message do |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 pipe:write(str); |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 end |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 return pipe:close(); |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 end |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 return smtp.send({ |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 user = config.user; password = config.password; |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 server = config.server; port = config.port; |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 domain = config.domain; |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 from = config.origin; rcpt = to; |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 source = message; |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 }); |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 assert(not moduleapi.send_email, "another email module is already loaded"); |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 function moduleapi:send_email(email) --luacheck: ignore 212/self |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 return send_email(email.to, email.headers or email.subject, email.body); |
74d7e59b3511
mod_email: Initial prototype module that allows other modules to send email
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 end |