1、修复邮件插入失败
2、插件支持设置页面
3、修复pop3邮箱拉取权限判断
4、修复非管理员账户的附件权限判断

Co-authored-by: jinnrry <i@jinnrry.com>
This commit is contained in:
Jinnrryandjinnrry authored and GitHub committed 2024-07-27 20:47:42 +08:00
1 parent 729eb9658a
commit e6a56b199d
28 files changed
+432 -224

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@
"SSLPublicKeyPath": "./config/ssl/public.crt",
"dbDSN": "./config/pmail_temp.db",
"dbType": "sqlite",
"httpsEnabled": 1,
"httpsEnabled": 2,
"spamFilterLevel": 0,
"httpPort": 80,
"httpsPort": 443,
+46
View File
@@ -0,0 +1,46 @@
package controllers
import (
"github.com/Jinnrry/pmail/dto/response"
"github.com/Jinnrry/pmail/hooks"
"github.com/Jinnrry/pmail/utils/context"
"io"
"net/http"
"strings"
)
func GetPluginList(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
ret := []string{}
for s, _ := range hooks.HookList {
ret = append(ret, s)
}
response.NewSuccessResponse(ret).FPrint(w)
}
func SettingsHtml(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
args := strings.Split(req.RequestURI, "/")
if len(args) < 4 {
response.NewErrorResponse(response.ParamsError, "404", "").FPrint(w)
return
}
pluginName := args[4]
if plugin, ok := hooks.HookList[pluginName]; ok {
dt, err := io.ReadAll(req.Body)
if err != nil {
response.NewErrorResponse(response.ParamsError, err.Error(), "").FPrint(w)
return
}
html := plugin.SettingsHtml(ctx,
strings.Join(args[4:], "/"),
string(dt),
)
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write([]byte(html))
return
}
response.NewErrorResponse(response.ParamsError, "404", "")
}
+3 -1
View File
@@ -54,15 +54,17 @@ type Email struct {
Date string
Status int // 0未发送,1已发送,2发送失败,3删除
MessageId int64
Size int
}
func NewEmailFromReader(to []string, r io.Reader) *Email {
func NewEmailFromReader(to []string, r io.Reader, size int) *Email {
ret := &Email{}
m, err := message.Read(r)
if err != nil {
log.Errorf("email解析错误! Error %+v", err)
}
ret.Size = size
ret.From = buildUser(m.Header.Get("From"))
if len(to) > 0 {
+45 -2
View File
@@ -137,6 +137,47 @@ func (h *HookSender) ReceiveParseAfter(ctx *context.Context, email *parsemail.Em
}
// GetName 获取插件名称
func (h *HookSender) GetName(ctx *context.Context) string {
dto := framework.HookDTO{
Ctx: ctx,
}
body, _ := json.Marshal(dto)
ret, errL := h.httpc.Post("http://plugin/GetName", "application/json", strings.NewReader(string(body)))
if errL != nil {
log.WithContext(ctx).Errorf("[%s] Error! %v", h.name, errL)
return ""
}
body, _ = io.ReadAll(ret.Body)
return string(body)
}
// SettingsHtml 插件页面
func (h *HookSender) SettingsHtml(ctx *context.Context, url string, requestData string) string {
dto := framework.SettingsHtmlRequest{
Ctx: ctx,
URL: url,
RequestData: requestData,
}
body, _ := json.Marshal(dto)
ret, errL := h.httpc.Post("http://plugin/SettingsHtml", "application/json", strings.NewReader(string(body)))
if errL != nil {
log.WithContext(ctx).Errorf("[%s] Error! %v", h.name, errL)
return ""
}
body, _ = io.ReadAll(ret.Body)
return string(body)
}
func NewHookSender(socketPath string, name string, serverVersion string) *HookSender {
httpc := http.Client{
Timeout: time.Second * 10,
@@ -214,8 +255,10 @@ func Init(serverVersion string) {
}
}
if loadSucc {
HookList[info.Name()] = NewHookSender(socketPath, info.Name(), serverVersion)
log.Infof("[%s] Plugin Load Success!", info.Name())
hk := NewHookSender(socketPath, info.Name(), serverVersion)
hkName := hk.GetName(&context.Context{})
HookList[hkName] = hk
log.Infof("[%s] Plugin Load Success!", hkName)
}
}
+37
View File
@@ -13,6 +13,7 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
"time"
)
@@ -27,6 +28,10 @@ type EmailHook interface {
ReceiveParseAfter(ctx *context.Context, email *parsemail.Email)
// ReceiveSaveAfter 邮件落库以后执行(收信规则后执行) 异步执行
ReceiveSaveAfter(ctx *context.Context, email *parsemail.Email, ue []*models.UserEmail)
// GetName 获取插件名称
GetName(ctx *context.Context) string
// SettingsHtml 插件页面
SettingsHtml(ctx *context.Context, url string, requestData string) string
}
// HookDTO PMail 主程序和插件通信的结构体
@@ -39,6 +44,12 @@ type HookDTO struct {
UserEmail []*models.UserEmail
}
type SettingsHtmlRequest struct {
Ctx *context.Context // 上下文
URL string
RequestData string
}
type Plugin struct {
name string
hook EmailHook
@@ -160,6 +171,32 @@ func (p *Plugin) Run() {
writer.Write(body)
log.Debugf("[%s] ReceiveSaveAfter End", p.name)
})
mux.HandleFunc("/GetName", func(writer http.ResponseWriter, request *http.Request) {
log.Debugf("[%s] GetName Start", p.name)
var hookDTO HookDTO
body, _ := io.ReadAll(request.Body)
err := json.Unmarshal(body, &hookDTO)
if err != nil {
log.Errorf("params error %+v", err)
return
}
name := strings.ReplaceAll(p.hook.GetName(hookDTO.Ctx), " ", "")
writer.Write([]byte(name))
log.Debugf("[%s] GetName End", p.name)
})
mux.HandleFunc("/SettingsHtml", func(writer http.ResponseWriter, request *http.Request) {
log.Debugf("[%s] SettingsHtml Start", p.name)
var hookDTO SettingsHtmlRequest
body, _ := io.ReadAll(request.Body)
err := json.Unmarshal(body, &hookDTO)
if err != nil {
log.Errorf("params error %+v", err)
return
}
html := p.hook.SettingsHtml(hookDTO.Ctx, hookDTO.URL, hookDTO.RequestData)
writer.Write([]byte(html))
log.Debugf("[%s] SettingsHtml End", p.name)
})
server := http.Server{
ReadTimeout: 5 * time.Second,
+3 -8
View File
@@ -52,16 +52,11 @@ curl -X POST http://localhost:8501/v1/models/emotion_model:predict -d '{
4、将spam_block插件移动到pmail插件目录
5、在插件位置新建配置文件`spam_block_config.json`内容类似
5、设置插件
```json
{
"apiURL": "http://localhost:8501/v1/models/emotion_model:predict",
"apiTimeout": 3000
}
```
PMail后台->右上角设置按钮->插件设置->SpamBlock
apiURL表示模型api访问地址,如果你是使用Docker部署,PMail和tensorflow/serving容器需要设置为相同网络才能通信,并且需要把localhost替换为tensorflow/serving的容器名称
接口地址表示模型api访问地址,如果你是使用Docker部署,PMail和tensorflow/serving容器需要设置为相同网络才能通信,并且需要把localhost替换为tensorflow/serving的容器名称
# 模型效果
File renamed without changes.
+3 -1
View File
@@ -1,4 +1,6 @@
datasets==2.20.0
numpy==1.20.3
retvec==1.0.1
tensorflow==2.8.4
tensorflow==2.12.1
beautifulsoup4
lxml
+77 -17
View File
@@ -1,6 +1,7 @@
package main
import (
_ "embed"
"encoding/json"
"fmt"
"github.com/Jinnrry/pmail/dto/parsemail"
@@ -9,6 +10,7 @@ import (
"github.com/Jinnrry/pmail/models"
"github.com/Jinnrry/pmail/utils/context"
log "github.com/sirupsen/logrus"
"github.com/spf13/cast"
"io"
"net/http"
"os"
@@ -21,15 +23,64 @@ type SpamBlock struct {
hc *http.Client
}
func (s SpamBlock) SendBefore(ctx *context.Context, email *parsemail.Email) {
func (s *SpamBlock) SendBefore(ctx *context.Context, email *parsemail.Email) {
}
func (s SpamBlock) SendAfter(ctx *context.Context, email *parsemail.Email, err map[string]error) {
func (s *SpamBlock) SendAfter(ctx *context.Context, email *parsemail.Email, err map[string]error) {
}
func (s SpamBlock) ReceiveParseBefore(ctx *context.Context, email *[]byte) {
func (s *SpamBlock) ReceiveParseBefore(ctx *context.Context, email *[]byte) {
}
// GetName 获取插件名称
func (s *SpamBlock) GetName(ctx *context.Context) string {
return "SpamBlock"
}
//go:embed static/index.html
var index string
//go:embed static/jquery.js
var jquery string
// SettingsHtml 插件页面
func (s *SpamBlock) SettingsHtml(ctx *context.Context, url string, requestData string) string {
if strings.Contains(url, "jquery.js") {
return jquery
}
if strings.Contains(url, "index.html") {
if !ctx.IsAdmin {
return fmt.Sprintf(`
<div>
Please contact the administrator for configuration.
</div>
`)
}
return fmt.Sprintf(index, s.cfg.ApiURL, s.cfg.ApiTimeout, s.cfg.Threshold)
}
var cfg SpamBlockConfig
var tempCfg map[string]string
err := json.Unmarshal([]byte(requestData), &tempCfg)
if err != nil {
return err.Error()
}
cfg.ApiURL = tempCfg["url"]
cfg.Threshold = cast.ToFloat64(tempCfg["threshold"])
cfg.ApiTimeout = cast.ToInt(tempCfg["timeout"])
err = saveConfig(cfg)
if err != nil {
return err.Error()
}
s.cfg = cfg
return "success"
}
@@ -45,7 +96,11 @@ type InstanceItem struct {
Token []string `json:"token"`
}
func (s SpamBlock) ReceiveParseAfter(ctx *context.Context, email *parsemail.Email) {
func (s *SpamBlock) ReceiveParseAfter(ctx *context.Context, email *parsemail.Email) {
if s.cfg.ApiURL == "" {
return
}
reqData := ApiRequest{
Instances: []InstanceItem{
@@ -94,25 +149,26 @@ func (s SpamBlock) ReceiveParseAfter(ctx *context.Context, email *parsemail.Emai
switch maxClass {
case 0:
log.WithContext(ctx).Infof("[Spam Check Result: Normal] %s", email.Subject)
log.WithContext(ctx).Infof("[Spam Check Result: %f Normal] %s", maxScore, email.Subject)
case 1:
log.WithContext(ctx).Infof("[Spam Check Result: Spam ] %s", email.Subject)
log.WithContext(ctx).Infof("[Spam Check Result: %f Spam ] %s", maxScore, email.Subject)
case 2:
log.WithContext(ctx).Infof("[Spam Check Result: Blackmail ] %s", email.Subject)
log.WithContext(ctx).Infof("[Spam Check Result: %f Blackmail ] %s", maxScore, email.Subject)
}
if maxClass != 0 {
if maxClass != 0 && maxScore > s.cfg.Threshold/100 {
email.Status = 3
}
}
func (s SpamBlock) ReceiveSaveAfter(ctx *context.Context, email *parsemail.Email, ue []*models.UserEmail) {
func (s *SpamBlock) ReceiveSaveAfter(ctx *context.Context, email *parsemail.Email, ue []*models.UserEmail) {
}
type SpamBlockConfig struct {
ApiURL string `json:"apiURL"`
ApiTimeout int `json:"apiTimeout"` // 单位毫秒
ApiURL string `json:"apiURL"`
ApiTimeout int `json:"apiTimeout"` // 单位毫秒
Threshold float64 `json:"threshold"`
}
func NewSpamBlockHook() *SpamBlock {
@@ -123,20 +179,18 @@ func NewSpamBlockHook() *SpamBlock {
if err == nil {
json.Unmarshal(cfgData, &pluginConfig)
}
} else {
log.Infof("No Config file found")
return nil
}
log.Infof("Config: %+v", pluginConfig)
if pluginConfig.ApiURL == "" {
pluginConfig.ApiURL = "http://localhost:8501/v1/models/emotion_model:predict"
}
if pluginConfig.ApiTimeout == 0 {
pluginConfig.ApiTimeout = 3000
}
if pluginConfig.Threshold == 0 {
pluginConfig.Threshold = 80
}
hc := &http.Client{
Timeout: time.Duration(pluginConfig.ApiTimeout) * time.Millisecond,
}
@@ -147,6 +201,12 @@ func NewSpamBlockHook() *SpamBlock {
}
}
func saveConfig(cfg SpamBlockConfig) error {
data, _ := json.Marshal(cfg)
err := os.WriteFile("./plugins/spam_block_config.json", data, 0777)
return err
}
func main() {
log.Infof("SpamBlockPlug Star Success")
instance := NewSpamBlockHook()
+53
View File
@@ -0,0 +1,53 @@
<html>
<header>
<script src="/api/plugin/settings/SpamBlock/jquery.js"></script>
<script>
$(function () {
$("#submit").click(function () {
let data = {};
let value = $('#form').serializeArray();
$.each(value, function (index, item) {
data[item.name] = item.value;
});
let jsonData = JSON.stringify(data);
console.log(jsonData);
$.post("/api/plugin/settings/SpamBlock/save", jsonData, function (data) {
alert(data)
})
})
})
</script>
</header>
<body>
<div>
<form id="form" action="/api/plugin/settings/SpamBlock/save" method="post">
<div>
<label for="url"> 模型API接口地址: </label>
<input id="url" style="width: 600px;" name="url" value="%s"
placeholder="http://localhost:8501/v1/models/emotion_model:predict">
</div>
<div>
<label for="timeout"> 超时时间: </label>
<input id="timeout" style="width: 600px;" name="timeout" value="%d" placeholder="单位毫秒">
</div>
<div>
<label for="threshold"> 识别阈值: </label>
<input id="threshold" name="threshold" type="number" value="%f" style="width: 600px;"
step=".01" max="100" min="0" placeholder="识别阈值,值越低过滤越严格,越容易误判">
</div>
<input id="submit" type="button" value="Submit"/>
</form>
</div>
</body>
</html>
+2
View File
@@ -0,0 +1,2 @@
/*! jQuery v3.7.1 | (c) OpenJS Foundation and other contributors | jquery.org/license */
!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(ie,e){"use strict";var oe=[],r=Object.getPrototypeOf,ae=oe.slice,g=oe.flat?function(e){return oe.flat.call(e)}:function(e){return oe.concat.apply([],e)},s=oe.push,se=oe.indexOf,n={},i=n.toString,ue=n.hasOwnProperty,o=ue.toString,a=o.call(Object),le={},v=function(e){return"function"==typeof e&&"number"!=typeof e.nodeType&&"function"!=typeof e.item},y=function(e){return null!=e&&e===e.window},C=ie.document,u={type:!0,src:!0,nonce:!0,noModule:!0};function m(e,t,n){var r,i,o=(n=n||C).createElement("script");if(o.text=e,t)for(r in u)(i=t[r]||t.getAttribute&&t.getAttribute(r))&&o.setAttribute(r,i);n.head.appendChild(o).parentNode.removeChild(o)}function x(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?n[i.call(e)]||"object":typeof e}var t="3.7.1",l=/HTML$/i,ce=function(e,t){return new ce.fn.init(e,t)};function c(e){var t=!!e&&"length"in e&&e.length,n=x(e);return!v(e)&&!y(e)&&("array"===n||0===t||"number"==typeof t&&0<t&&t-1 in e)}function fe(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()}ce.fn=ce.prototype={jquery:t,constructor:ce,length:0,toArray:function(){return ae.call(this)},get:function(e){return null==e?ae.call(this):e<0?this[e+this.length]:this[e]},pushStack:function(e){var t=ce.merge(this.constructor(),e);return t.prevObject=this,t},each:function(e){return ce.each(this,e)},map:function(n){return this.pushStack(ce.map(this,function(e,t){return n.call(e,t,e)}))},slice:function(){return this.pushStack(ae.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},even:function(){return this.pushStack(ce.grep(this,function(e,t){return(t+1)%2}))},odd:function(){return this.pushStack(ce.grep(this,function(e,t){return t%2}))},eq:function(e){var t=this.length,n=+e+(e<0?t:0);return this.pushStack(0<=n&&n<t?[this[n]]:[])},end:function(){return this.prevObject||this.constructor()},push:s,sort:oe.sort,splice:oe.splice},ce.extend=ce.fn.extend=function(){var e,t,n,r,i,o,a=arguments[0]||{},s=1,u=arguments.length,l=!1;for("boolean"==typeof a&&(l=a,a=arguments[s]||{},s++),"object"==typeof a||v(a)||(a={}),s===u&&(a=this,s--);s<u;s++)if(null!=(e=arguments[s]))for(t in e)r=e[t],"__proto__"!==t&&a!==r&&(l&&r&&(ce.isPlainObject(r)||(i=Array.isArray(r)))?(n=a[t],o=i&&!Array.isArray(n)?[]:i||ce.isPlainObject(n)?n:{},i=!1,a[t]=ce.extend(l,o,r)):void 0!==r&&(a[t]=r));return a},ce.extend({expando:"jQuery"+(t+Math.random()).replace(/\D/g,""),isReady:!0,error:function(e){throw new Error(e)},noop:function(){},isPlainObject:function(e){var t,n;return!(!e||"[object Object]"!==i.call(e))&&(!(t=r(e))||"function"==typeof(n=ue.call(t,"constructor")&&t.constructor)&&o.call(n)===a)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},globalEval:function(e,t,n){m(e,{nonce:t&&t.nonce},n)},each:function(e,t){var n,r=0;if(c(e)){for(n=e.length;r<n;r++)if(!1===t.call(e[r],r,e[r]))break}else for(r in e)if(!1===t.call(e[r],r,e[r]))break;return e},text:function(e){var t,n="",r=0,i=e.nodeType;if(!i)while(t=e[r++])n+=ce.text(t);return 1===i||11===i?e.textContent:9===i?e.documentElement.textContent:3===i||4===i?e.nodeValue:n},makeArray:function(e,t){var n=t||[];return null!=e&&(c(Object(e))?ce.merge(n,"string"==typeof e?[e]:e):s.call(n,e)),n},inArray:function(e,t,n){return null==t?-1:se.call(t,e,n)},isXMLDoc:function(e){var t=e&&e.namespaceURI,n=e&&(e.ownerDocument||e).documentElement;return!l.test(t||n&&n.nodeName||"HTML")},merge:function(e,t){for(var n=+t.length,r=0,i=e.length;r<n;r++)e[i++]=t[r];return e.length=i,e},grep:function(e,t,n){for(var r=[],i=0,o=e.length,a=!n;i<o;i++)!t(e[i],i)!==a&&r.push(e[i]);return r},map:function(e,t,n){var r,i,o=0,a=[];if(c(e))for(r=e.length;o<r;o++)null!=(i=t(e[o],o,n))&&a.push(i);else for(o in e)null!=(i=t(e[o],o,n))&&a.push(i);return g(a)},guid:1,support:le}),"function"==typeof Symbol&&(ce.fn[Symbol.iterator]=oe[Symbol.iterator]),ce.each("Boolean Number String Function Array Date RegExp Object Error Symbol".split(" "),function(e,t){n["[object "+t+"]"]=t.toLowerCase()});var pe=oe.pop,de=oe.sort,he=oe.splice,ge="[\\x20\\t\\r\\n\\f]",ve=new RegExp("^"+ge+"+|((?:^|[^\\\\])(?:\\\\.)*)"+ge+"+$","g");ce.contains=function(e,t){var n=t&&t.parentNode;return e===n||!(!n||1!==n.nodeType||!(e.contains?e.contains(n):e.compareDocumentPosition&&16&e.compareDocumentPosition(n)))};var f=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g;function p(e,t){return t?"\0"===e?"\ufffd":e.slice(0,-1)+"\\"+e.charCodeAt(e.length-1).toString(16)+" ":"\\"+e}ce.escapeSelector=function(e){return(e+"").replace(f,p)};var ye=C,me=s;!function(){var e,b,w,o,a,T,r,C,d,i,k=me,S=ce.expando,E=0,n=0,s=W(),c=W(),u=W(),h=W(),l=function(e,t){return e===t&&(a=!0),0},f="checked|selected|async|autofocus|autoplay|conLine truncated
+2
View File
@@ -24,6 +24,8 @@ def getData(folder_path):
# 读取csv文件内容
with open(file_path, 'r', errors='ignore') as csv_file:
for line in csv_file:
if line[0] == '' or line[0]==' ':
continue
labels.append([int(str.strip(line[0]))])
msgs.append(line[3:])
return np.array(msgs), np.array(labels)
@@ -1,5 +1,3 @@
0 Hello hello
0 Hello hello
1 Get the chance to win a GoLand subscription by sharing your feedback JetBrains: Developer Tools for Professionals and Teams-->96We’d love to hear your feedback about all of the changes. Please take a moment to complete our short survey.&#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847;&#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847;&#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847;&#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847;&#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847;&#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847; &#847;&nbsp;&nbsp;&nbsp;&nbsp;JetBrains Research&nbsp;&nbsp;GoLand 2024.2 EAP: New Features and Improvements SurveyShare your feedback&nbsp;Greetings from JetBrains!We hope you've been enjoying the new features in the GoLand EAP builds. We’d love to hear your feedback about all of the changes. Please take a moment to complete our shortsurvey.By completing the survey and providing us with your contact information, you will be automatically entered into our prize draw. The winners will be picked at random, and each winner will receive one of threeone-year individual GoLand subscriptions.If you haven’t yet tried the latest EAP build, you can download ithere.Best regards,The JetBrains GoLand teamThe Drive to Develop&nbsp;Mail preferences&nbsp;| &nbsp;Unsubscribe&nbsp;| &nbsp;Privacy policyYou have received this email because you gave us permission to contact you for feedback about the GoLand EAP.Our mailing address: JetBrains s.r.o.,Na Hřebenech II 1718/8, 14000 Prague 4, Czech Republic
0 Re: [Jinnrry/PMail] 请问如何设置PMail和nginx reverse proxy? (Issue #151) 之前mx记录弄错了现在出现了timeoutyeeler@origin:~/PMail/server$ docker compose upWARN[0000] /home/yeeler/PMail/server/docker-compose.yml:versionis obsolete[+] Running 1/0✔ Container server-pmail-1Created0.0sAttaching to pmail-1pmail-1| [info][2024-07-10 21:26:42][/work/main.go:81]*******************************************************************pmail-1| [info][2024-07-10 21:26:42][/work/main.go:82]*** Server Start Successpmail-1|pmail-1| [info][2024-07-10 21:26:42][/work/main.go:83]*** Server Version: v2.5.3pmail-1|pmail-1| [info][2024-07-10 21:26:42][/work/main.go:84]*** Git Commit Hash:402e001pmail-1| [info][2024-07-10 21:26:42][/work/main.go:85]*** Build Date: 2024-07-08 16:49:03pmail-1| [info][2024-07-10 21:26:42][/work/main.go:86]*** Build GoLang Version: go version go1.22.5 linux/amd64pmail-1| [info][2024-07-10 21:26:42][/work/main.go:87]*******************************************************************pmail-1| [info][2024-07-10 21:26:42][/work/hooks/base.go:181][telegram_push] Plugin Loadpmail-1| [telegram_push] Plugin Start! PID:12[info][2024-07-10 21:26:43][/work/hooks/base.go:213][telegram_push] Plugin Load Success!pmail-1| [info][2024-07-10 21:26:43][/work/hooks/base.go:181][web_push] Plugin Loadpmail-1| [web_push] Plugin Start! PID:16[info][2024-07-10 21:26:44][/work/hooks/base.go:213][web_push] Plugin Load Success!pmail-1| [info][2024-07-10 21:26:44][/work/hooks/base.go:181][wechat_push] Plugin Loadpmail-1| [wechat_push] Plugin Start! PID:21[info][2024-07-10 21:26:45][/work/hooks/base.go:213][wechat_push] Plugin Load Success!pmail-1| [warning][2024-07-10 21:26:45][/work/res_init/init.go:52]Config File Info:{"logLevel":"debug","domain":"aaa.com","domains":["aaa.com"],"webDomain":"email.aaa.com","dkimPrivateKeyPath":"config/dkim/dkim.priv","sslType":"1","SSLPrivateKeyPath":"./config/ssl/private.key","SSLPublicKeyPath":"./config/ssl/public.crt","dbDSN":"./config/pmail_temp.db","dbType":"sqlite","httpsEnabled":2,"spamFilterLevel":0,"httpPort":80,"httpsPort":443,"weChatPushAppId":"","weChatPushSecret":"","weChatPushTemplateId":"","weChatPushUserId":"","tgBotToken":"","tgChatId":"","isInit":true,"webPushUrl":"","webPushToken":""}pmail-1| [info][2024-07-10 21:26:45][/work/pop3_server/pop3server.go:27]POP3 With TLS Server Start On Port :995pmail-1| [info][2024-07-10 21:26:45][/work/smtp_server/smtp.go:175]Starting Smtp Server Port: :25pmail-1| [info][2024-07-10 21:26:45][/work/http_server/http_server.go:80]HttpServer Start On Port :80pmail-1| [info][2024-07-10 21:26:45][/work/pop3_server/pop3server.go:46]POP3 Server Start On Port :110pmail-1| [info][2024-07-10 21:26:45][/work/smtp_server/smtp.go:147]Starting Smtp With SSL Server Port: :465pmail-1| [info][2024-07-10 21:27:09][c0a84002668e8c2d62c700014870dcb0][/work/controllers/email/send.go:57]发送邮件pmail-1| [debug][2024-07-10 21:27:09][c0a84002668e8c2d62c700014870dcb0][/work/controllers/email/send.go:152]插件执行--SendBeforepmail-1| [debug][2024-07-10 21:27:09][c0a84002668e8c2d62c700014870dcb0][/work/hooks/base.go:50][telegram_push]Plugin SendBefore Startpmail-1| [debug][2024-07-10 21:27:09][c0a84002668e8c2d62c700014870dcb0][/work/hooks/base.go:69][telegram_push]Plugin SendBefore Endpmail-1| [debug][2024-07-10 21:27:09][c0a84002668e8c2d62c700014870dcb0][/work/hooks/base.go:50][web_push]Plugin SendBefore Startpmail-1| [debug][2024-07-10 21:27:09][c0a84002668e8c2d62c700014870dcb0][/work/hooks/base.go:69][web_push]Plugin SendBefore Endpmail-1| [debug][2024-07-10 21:27:09][c0a84002668e8c2d62c700014870dcb0][/work/hooks/base.go:50][wechat_push]Plugin SendBefore Startpmail-1| [debug][2024-07-10 21:27:09][c0a84002668e8c2d62c700014870dcb0][/work/hooks/base.go:69][wechat_push]Plugin SendBefore Endpmail-1| [debug][2024-07-10 21:27:09][c0a84002668e8c2d62c700014870dcb0][/work/controllers/email/send.go:159]插件执行--SendBefore Endpmail-1| [debug][2024-07-10 21:27:09][c0a84002668e8c2d62c700014870dcb0][/work/utils/send/send.go:126]Message Infos : DKIM-Signature: a=rsa-sha256; bh=LmOUdOOQ1/nljnKoO+A4LqHI/wp0btxn1QU+LJ6q/KM=;pmail-1|c=simple/simple; d=aaa.com;pmail-1|h=Content-Type:Mime-Version:Subject:To:From:Message-Id:Date; s=default;pmail-1|t=1720618029; v=1;pmail-1|b=ajOTutt37JmYyfXot/+WtkQFNwsIjyqgjvVBCy6BeeR4GIj16gSBJUFfOvWtC/urV1Ns1NKFpmail-1|gCkkRknwgLnwGNhszgtgSZfBJ/C+G6QbMpBT3HGpan9zCLP/9dK28Rku3t5QXPffR/l/DhcIP1Mpmail-1|wLZ16N5inu8V1rJe6PolC8H0=pmail-1| Content-Type: multipart/mixed;pmail-1|boundary=86904f13d11768291e792468b471ea7ca9eaaf80733a3dd90a9da112bb2apmail-1| Mime-Version: 1.0pmail-1| Subject: 44444444444pmail-1| To:yeeler@21cn.compmail-1| From: "admin"admin@aaa.compmail-1| Message-Id:10@aaa.compmail-1| Date: Wed, 10 Jul 2024 21:27:09 +0800pmail-1|pmail-1| --86904f13d11768291e792468b471ea7ca9eaaf80733a3dd90a9da112bb2apmail-1| Content-Type: multipart/alternative;pmail-1|boundary=b49b13e6359823c5cfe3ec38d9e0acc316219598eb38698056dc13a0e64cpmLine truncated
2 关于公司职员劳补福利津贴申领通知! 各位同事:具体详细请查阅附件!
+57
View File
@@ -0,0 +1,57 @@
import os
from email.parser import Parser
from email.policy import default
from bs4 import BeautifulSoup
# 该脚本用于整理trec06c数据集,可以生成训练集和测试集数据格式
def getData(path):
f = open(path, 'r', errors='ignore')
data = f.read()
headers = Parser(policy=default).parsestr(data)
body = ""
if headers.is_multipart():
for part in headers.iter_parts():
tbody = part.get_payload()
if isinstance(tbody, list):
for item in tbody:
txt = item.get_payload()
if isinstance(tbody, list):
return "", ""
bsObj = BeautifulSoup(txt, 'lxml')
body += bsObj.get_text()
else:
bsObj = BeautifulSoup(tbody, 'lxml')
body += bsObj.get_text()
else:
tbody = headers.get_payload()
bsObj = BeautifulSoup(tbody, 'lxml')
body += bsObj.get_text()
return headers["subject"], body.replace("\n", "")
num = 0
# getData("../data/000/000")
with open("index", "r") as f:
with open("trec07p_train.csv", "w") as w:
with open("trec07p_test.csv", "w") as wt:
while True:
line = f.readline()
if not line:
break
infos = line.split(" ")
subject, body = getData(infos[1].strip())
if subject == "":
continue
tp = 0
if infos[0].lower() == "spam":
tp = 1
data = "{} \t{} {}\n".format(tp, subject, body)
if num < 55000:
w.write(data)
else:
wt.write(data)
num += 1
print(num)
@@ -35,6 +35,20 @@ func (w *TelegramPushHook) ReceiveSaveAfter(ctx *context.Context, email *parsema
}
// GetName 获取插件名称
func (w *TelegramPushHook) GetName(ctx *context.Context) string {
return "TgPush"
}
// SettingsHtml 插件页面
func (w *TelegramPushHook) SettingsHtml(ctx *context.Context, url string, requestData string) string {
return fmt.Sprintf(`
<div>
TG push No Settings Page
</div>
`)
}
func (w *TelegramPushHook) SendBefore(ctx *context.Context, email *parsemail.Email) {
}
-14
View File
@@ -1,14 +0,0 @@
## How To Ues
Copy plugin binary file to `/plugins`
add config.json to `/plugins/config.com` like this:
```json
{
"webPushUrl": "", // webhook push URL
"webPushToken": "", // webhook push token
}
```
-136
View File
@@ -1,136 +0,0 @@
package main
import (
"bytes"
"encoding/json"
"github.com/Jinnrry/pmail/config"
"github.com/Jinnrry/pmail/dto/parsemail"
"github.com/Jinnrry/pmail/hooks/framework"
"github.com/Jinnrry/pmail/models"
"github.com/Jinnrry/pmail/utils/context"
log "github.com/sirupsen/logrus"
"net/http"
"os"
)
type WebPushHook struct {
url string
token string
}
func (w *WebPushHook) ReceiveSaveAfter(ctx *context.Context, email *parsemail.Email, ue []*models.UserEmail) {
if w.url == "" {
return
}
content := string(email.Text)
if content == "" {
content = email.Subject
}
webhookURL := w.url // 替换为您的 Webhook URL
to := make([]string, len(email.To))
for i, user := range email.To {
to[i] = user.EmailAddress
}
data := EmailData{
From: email.From.EmailAddress,
To: to,
Subject: email.Subject,
Body: content,
Token: w.token,
}
jsonData, err := json.Marshal(data)
if err != nil {
log.WithContext(ctx).Errorf("web push error %+v", err)
}
resp, err := http.Post(webhookURL, "application/json", bytes.NewBuffer(jsonData))
if err != nil {
log.WithContext(ctx).Errorf("web push error %+v", err)
}
defer resp.Body.Close()
}
// EmailData 用于存储解析后的邮件数据
type EmailData struct {
From string `json:"from"`
To []string `json:"to"`
Subject string `json:"subject"`
Body string `json:"body"`
Token string `json:"token"`
}
func (w *WebPushHook) SendBefore(ctx *context.Context, email *parsemail.Email) {
}
func (w *WebPushHook) SendAfter(ctx *context.Context, email *parsemail.Email, err map[string]error) {
}
func (w *WebPushHook) ReceiveParseBefore(ctx *context.Context, email *[]byte) {
}
func (w *WebPushHook) ReceiveParseAfter(ctx *context.Context, email *parsemail.Email) {
}
type Config struct {
WebPushUrl string `json:"webPushUrl"`
WebPushToken string `json:"webPushToken"`
}
func NewWebPushHook() *WebPushHook {
var cfgData []byte
var err error
cfgData, err = os.ReadFile("./config/config.json")
if err != nil {
panic(err)
}
var mainConfig *config.Config
err = json.Unmarshal(cfgData, &mainConfig)
if err != nil {
panic(err)
}
var pluginConfig *Config
if _, err := os.Stat("./plugins/web_push_config.json"); err == nil {
cfgData, err = os.ReadFile("./plugins/web_push_config.json")
if err != nil {
panic(err)
}
err = json.Unmarshal(cfgData, &pluginConfig)
if err != nil {
panic(err)
}
}
token := ""
pushURL := ""
if pluginConfig != nil {
pushURL = pluginConfig.WebPushUrl
token = pluginConfig.WebPushToken
} else {
pushURL = mainConfig.WebPushUrl
token = mainConfig.WebPushToken
}
ret := &WebPushHook{
url: pushURL,
token: token,
}
return ret
}
func main() {
framework.CreatePlugin("web_push", NewWebPushHook()).Run()
}
+13
View File
@@ -32,6 +32,19 @@ type WeChatPushHook struct {
mainConfig *config.Config
}
func (w *WeChatPushHook) GetName(ctx *context.Context) string {
return "WeChatPushHook"
}
// SettingsHtml 插件页面
func (w *WeChatPushHook) SettingsHtml(ctx *context.Context, url string, requestData string) string {
return fmt.Sprintf(`
<div>
TG push No Settings Page
</div>
`)
}
func (w *WeChatPushHook) ReceiveSaveAfter(ctx *context.Context, email *parsemail.Email, ue []*models.UserEmail) {
if w.appId == "" || w.secret == "" || w.pushUser == "" {
return
+2
View File
@@ -54,6 +54,8 @@ func router(mux *http.ServeMux) {
mux.HandleFunc("/api/user/edit", contextIterceptor(controllers.EditUser))
mux.HandleFunc("/api/user/info", contextIterceptor(controllers.Info))
mux.HandleFunc("/api/user/list", contextIterceptor(controllers.UserList))
mux.HandleFunc("/api/plugin/settings/", contextIterceptor(controllers.SettingsHtml))
mux.HandleFunc("/api/plugin/list", contextIterceptor(controllers.GetPluginList))
}
func HttpStart() {
+6 -9
View File
@@ -185,15 +185,12 @@ func (a action) Uidl(session *gopop.Session, msg string) ([]gopop.UidlItem, erro
var res []listItem
var err error
var ssql string
err = db.Instance.Where("type=0 and status=0").Select("id").Table("email").Find(&res)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
log.WithContext(session.Ctx.(*context.Context)).Errorf("SQL:%s Error: %+v", ssql, err)
err = nil
return []gopop.UidlItem{}, nil
emailList, _ := list.GetEmailList(session.Ctx.(*context.Context), dto.SearchTag{Type: consts.EmailTypeReceive, Status: -1, GroupId: -1}, "", true, 0, 99999)
for _, info := range emailList {
res = append(res, listItem{
Id: cast.ToInt64(info.Id),
Size: cast.ToInt64(info.Size),
})
}
ret := []gopop.UidlItem{}
for _, re := range res {
+3 -3
View File
@@ -20,14 +20,14 @@ func HasAuth(ctx *context.Context, email *models.Email) bool {
if ctx.IsAdmin {
return true
}
var ue *models.UserEmail
err := db.Instance.Where("email_id = ?", email.Id).Find(&ue)
var ue []models.UserEmail
err := db.Instance.Table(&models.UserEmail{}).Where("email_id = ? and user_id = ?", email.Id, ctx.UserID).Find(&ue)
if err != nil {
log.Errorf("Error while checking user: %v", err)
return false
}
return ue != nil
return len(ue) != 0
}
func DkimGen() string {
+21 -19
View File
@@ -46,7 +46,7 @@ func (s *Session) Data(r io.Reader) error {
}
log.WithContext(ctx).Debugf("开始执行插件ReceiveParseBefore End!")
email := parsemail.NewEmailFromReader(s.To, bytes.NewReader(emailData))
email := parsemail.NewEmailFromReader(s.To, bytes.NewReader(emailData), len(emailData))
if s.From != "" {
from := parsemail.BuilderUser(s.From)
@@ -209,24 +209,26 @@ func saveEmail(ctx *context.Context, size int, email *parsemail.Email, sendUserI
}
modelEmail := models.Email{
Type: cast.ToInt8(emailType),
Subject: email.Subject,
ReplyTo: json2string(email.ReplyTo),
FromName: email.From.Name,
FromAddress: email.From.EmailAddress,
To: json2string(email.To),
Bcc: json2string(email.Bcc),
Cc: json2string(email.Cc),
Text: sql.NullString{String: string(email.Text), Valid: true},
Html: sql.NullString{String: string(email.HTML), Valid: true},
Sender: json2string(email.Sender),
Attachments: json2string(email.Attachments),
SPFCheck: spfV,
DKIMCheck: dkimV,
SendUserID: sendUserID,
SendDate: time.Now(),
Status: cast.ToInt8(email.Status),
CreateTime: time.Now(),
Type: cast.ToInt8(emailType),
Subject: email.Subject,
ReplyTo: json2string(email.ReplyTo),
FromName: email.From.Name,
FromAddress: email.From.EmailAddress,
To: json2string(email.To),
Bcc: json2string(email.Bcc),
Cc: json2string(email.Cc),
Text: sql.NullString{String: string(email.Text), Valid: true},
Html: sql.NullString{String: string(email.HTML), Valid: true},
Sender: json2string(email.Sender),
Attachments: json2string(email.Attachments),
Size: email.Size,
SPFCheck: spfV,
DKIMCheck: dkimV,
SendUserID: sendUserID,
SendDate: time.Now(),
Status: cast.ToInt8(email.Status),
CreateTime: time.Now(),
CronSendTime: time.Now(),
}
_, err := db.Instance.Insert(&modelEmail)