enable sendmail in blogger

This commit is contained in:
lxsang 2019-06-13 11:06:38 +02:00
parent 8a9941f6ed
commit 9b75bc4ca2
7 changed files with 120 additions and 4 deletions

View File

@ -113,7 +113,7 @@ pkgar:
test -f $(BUILDDIR)/packages/$$PKG/main.js && uglifyjs $(BUILDDIR)/packages/$$PKG/main.js --compress --mangle --output $(BUILDDIR)/packages/$$PKG/main.js;\ test -f $(BUILDDIR)/packages/$$PKG/main.js && uglifyjs $(BUILDDIR)/packages/$$PKG/main.js --compress --mangle --output $(BUILDDIR)/packages/$$PKG/main.js;\
test -f $(BUILDDIR)/packages/$$PKG/main.css && uglifycss --output $(BUILDDIR)/packages/$$PKG/main.css $(BUILDDIR)/packages/$$PKG/main.css;\ test -f $(BUILDDIR)/packages/$$PKG/main.css && uglifycss --output $(BUILDDIR)/packages/$$PKG/main.css $(BUILDDIR)/packages/$$PKG/main.css;\
cd $(BUILDDIR)/packages/$$PKG && zip -r "$$PKG.zip" ./ ; \ cd $(BUILDDIR)/packages/$$PKG && zip -r "$$PKG.zip" ./ ; \
cd ../../ && (mkdir repo/$$PKG || true) && mv packages/$$PKG/"$$PKG.zip" repo/$$PKG && touch repo/$$PKG/$$PKG.md && rm -r packages/$$PKG cd ../../ && (test -d repo/$$PKG || mkdir repo/$$PKG) && mv packages/$$PKG/"$$PKG.zip" repo/$$PKG && touch repo/$$PKG/$$PKG.md && rm -r packages/$$PKG
uglify: uglify:
# uglify antos.js # uglify antos.js

View File

@ -4,7 +4,7 @@ jsfiles = katex/katex.js katex/auto-render.js
cssfiles = main.css katex/katex.css cssfiles = main.css katex/katex.css
copyfiles = scheme.html cvsection.html package.json katex/fonts copyfiles = scheme.html cvsection.html package.json katex/fonts api/sendmail.lua sendmail.html
PKG_NAME=Blogger PKG_NAME=Blogger

View File

@ -0,0 +1,17 @@
local data = ...
print(data.content)
for k,v in pairs(data.to) do
print("sent to:"..v)
local to = v
local from = "From: xsang.le@gmail.com\n"
local suject = "Subject: " .. data.title .. "\n"
local content = data.content.."\n"
local cmd = 'echo "' .. utils.escape(from .. suject .. content) .. '"| sendmail ' .. to
--print(cmd)
local r = os.execute(cmd)
if not r then
print("Cannot send mail to: "..v)
end
end
return "Email sent"

View File

@ -106,3 +106,71 @@ class BloggerCVSectionDiaglog extends this.OS.GUI.BaseDialog
children = ($ container).children() children = ($ container).children()
cheight = ($ container).height() - 30 cheight = ($ container).height() - 30
($ children[1]).css("height", cheight + "px") ($ children[1]).css("height", cheight + "px")
# this dialog is for send mail
class BloggerSendmailDiaglog extends this.OS.GUI.BaseDialog
constructor: () ->
super "BloggerCVSectionDiaglog"
init: () ->
@render "#{@path()}/sendmail.html"
@subdb = new @.parent._api.DB("subscribers")
main: () ->
# get db
me = @
@maillinglist = @find "email-list"
title = (new RegExp "^#+(.*)\n", "g").exec @data.content
(@find "mail-title").value = title[1]
content = (@data.content.substring 0, 500) + "..."
(@find "contentarea").value = BloggerSendmailDiaglog.template.format @data.id, content, @data.id
@subdb.find {}, (d) ->
return me.error __("Cannot fetch subscribers data: {0}", d.error) if d.error
for v in d.result
v.text = v.name
v.switch = true
v.checked = true
me.maillinglist.set "items", d.result
(@find "bt-sendmail").set "onbtclick", (e) ->
items = me.maillinglist.get "items"
emails = []
emails.push v.email for v in items when v.checked is true
return me.notify __("No email selected") if emails.length is 0
# send the email
data =
path: "#{me.parent.path()}/sendmail.lua",
parameters:
to: emails,
title: (me.find "mail-title").value,
content: (me.find "contentarea").value
me._api.post "system/apigateway", data, (d) ->
me.notify "Sendmail: {0}".format d
me.quit()
, (e, s) ->
console.log e
me.error __("Error sending mail: {0}", e.responseText)
BloggerSendmailDiaglog.template = """
Hello,
Xuan Sang LE has just published a new post on his blog: https://blog.lxsang.me/post/id/{0}
==========
{1}
==========
Read the full article via:
https://blog.lxsang.me/post/id/{2}
You receive this email because you have been subscribed to his blog.
Have a nice day,
Sent from Blogger, an AntOS application
"""

View File

@ -183,6 +183,17 @@ class Blogger extends this.OS.GUI.BaseApplication
SimpleMDE.togglePreview e SimpleMDE.togglePreview e
#/console.log me.select ".editor-preview editor-preview-active" #/console.log me.select ".editor-preview editor-preview-active"
renderMathInElement me.find "editor-container" renderMathInElement me.find "editor-container"
},
"|",
{
name: __("Send mail"),
className: "fa fa-paper-plane",
action: (e) ->
sel = me.bloglist.get "selected"
return me.error __("No post selected") unless sel
me.openDialog new BloggerSendmailDiaglog(), (d) ->
console.log "test"
, __("Send mail"), { content: me.editor.value(), id: sel.id }
} }
] ]
@bloglist.set "onlistselect", (e) -> @bloglist.set "onlistselect", (e) ->

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE", "author": "Xuan Sang LE",
"email": "xsang.le@gmail.com" "email": "xsang.le@gmail.com"
}, },
"version":"0.0.3-a", "version":"0.0.6-a",
"category":"Internet", "category":"Internet",
"iconclass":"fa fa-book", "iconclass":"fa fa-book",
"mimes":["none"] "mimes":["none"]

View File

@ -0,0 +1,20 @@
<afx-app-window data-id = "blogger-send-mail-win" apptitle="Send mail" width="500" height="400" resizable = "false">
<afx-hbox>
<afx-menu data-width="150" data-id="email-list"></afx-menu>
<afx-resizer data-width="3"></afx-resizer>
<div data-width="5"></div>
<afx-vbox >
<div data-height="5"></div>
<afx-label data-height="20" text = "__(Title)"></afx-label>
<input type = "text" data-height="20" name="title" data-id = "mail-title"/>
<afx-label data-height = "20" text = "Content" />
<textarea name="content" data-id = "contentarea" />
<div data-height="5"></div>
<afx-hbox data-height = "30">
<div></div>
<afx-button iconclass = "fa fa-paper-plane" data-id = "bt-sendmail" data-width="60" text = "__(Send)"/>
</afx-hbox>
</afx-vbox>
<div data-width="5"></div>
</afx-hbox>
</afx-app-window>