移除tg插件,增加第三方tg插件地址
This commit is contained in:
parent
778e279b4f
commit
e7bb01ae6d
@ -13,7 +13,6 @@ COPY . .
|
||||
COPY --from=febuild /work/dist /work/server/listen/http_server/dist
|
||||
RUN apk update && apk add git
|
||||
RUN cd /work/server && go build -ldflags "-s -w -X 'main.version=${VERSION}' -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail main.go
|
||||
RUN cd /work/server/hooks/telegram_push && go build -ldflags "-s -w" -o output/telegram_push telegram_push.go
|
||||
RUN cd /work/server/hooks/wechat_push && go build -ldflags "-s -w" -o output/wechat_push wechat_push.go
|
||||
RUN cd /work/server/hooks/spam_block && go build -ldflags "-s -w" -o output/spam_block spam_block.go
|
||||
|
||||
@ -30,7 +29,6 @@ RUN apk add --no-cache tzdata \
|
||||
|
||||
|
||||
COPY --from=serverbuild /work/server/pmail .
|
||||
COPY --from=serverbuild /work/server/hooks/telegram_push/output/* ./plugins/
|
||||
COPY --from=serverbuild /work/server/hooks/wechat_push/output/* ./plugins/
|
||||
COPY --from=serverbuild /work/server/hooks/spam_block/output/* ./plugins/
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@ COPY server .
|
||||
|
||||
RUN apk update && apk add git
|
||||
RUN go build -ldflags "-s -w -X 'main.version=${VERSION}' -X 'main.goVersion=$(go version)' -X 'main.gitHash=${GITHASH}' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail main.go
|
||||
RUN cd /work/hooks/telegram_push && go build -ldflags "-s -w" -o output/telegram_push telegram_push.go
|
||||
RUN cd /work/hooks/wechat_push && go build -ldflags "-s -w" -o output/wechat_push wechat_push.go
|
||||
RUN cd /work/hooks/spam_block && go build -ldflags "-s -w" -o output/spam_block spam_block.go
|
||||
|
||||
@ -24,7 +23,6 @@ RUN apk add --no-cache tzdata \
|
||||
|
||||
|
||||
COPY --from=serverbuild /work/pmail .
|
||||
COPY --from=serverbuild /work/hooks/telegram_push/output/* ./plugins/
|
||||
COPY --from=serverbuild /work/hooks/wechat_push/output/* ./plugins/
|
||||
COPY --from=serverbuild /work/hooks/spam_block/output/* ./plugins/
|
||||
|
||||
|
||||
13
Makefile
13
Makefile
@ -1,4 +1,4 @@
|
||||
build: build_fe build_server telegram_push web_push wechat_push package
|
||||
build: build_fe build_server spam_block wechat_push package
|
||||
|
||||
clean:
|
||||
rm -rf output
|
||||
@ -15,13 +15,6 @@ build_server:
|
||||
cd server && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail_mac_amd64 main.go
|
||||
cd server && CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail_mac_arm64 main.go
|
||||
|
||||
telegram_push:
|
||||
cd server/hooks/telegram_push && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o output/telegram_push_linux_amd64 telegram_push.go
|
||||
cd server/hooks/telegram_push && CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -o output/telegram_push_windows_amd64.exe telegram_push.go
|
||||
cd server/hooks/telegram_push && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" -o output/telegram_push_mac_amd64 telegram_push.go
|
||||
cd server/hooks/telegram_push && CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w" -o output/telegram_push_mac_arm64 telegram_push.go
|
||||
|
||||
|
||||
wechat_push:
|
||||
cd server/hooks/wechat_push && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o output/wechat_push_linux_amd64 wechat_push.go
|
||||
cd server/hooks/wechat_push && CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -o output/wechat_push_windows_amd64.exe wechat_push.go
|
||||
@ -36,7 +29,7 @@ spam_block:
|
||||
|
||||
|
||||
|
||||
plugin: telegram_push wechat_push
|
||||
plugin: spam_block wechat_push
|
||||
|
||||
|
||||
package: clean
|
||||
@ -47,7 +40,7 @@ package: clean
|
||||
cp -r server/config/dkim output/config/
|
||||
cp -r server/config/ssl output/config/
|
||||
cp -r server/config/config.json output/config/
|
||||
mv server/hooks/telegram_push/output/* output/plugins
|
||||
mv server/hooks/spam_block/output/* output/plugins
|
||||
mv server/hooks/wechat_push/output/* output/plugins
|
||||
cp README.md output/
|
||||
|
||||
|
||||
@ -111,9 +111,11 @@ IMAP Port: 993(SSL)
|
||||
|
||||
[WeChat Push](server/hooks/wechat_push/README.md)
|
||||
|
||||
[Telegram Push](server/hooks/telegram_push/README.md)
|
||||
[Spam Block](server/hooks/spam_block/README.md)
|
||||
|
||||
[Web Push](server/hooks/web_push/README.md)
|
||||
# Community plugins
|
||||
|
||||
[Telegram Push](https://github.com/ydzydzydz/pmail_telegram_push)
|
||||
|
||||
## Plugin Install
|
||||
> [!IMPORTANT]
|
||||
|
||||
@ -117,9 +117,11 @@ IMAP端口: 993(SSL)
|
||||
|
||||
[微信推送](server/hooks/wechat_push/README.md)
|
||||
|
||||
[Telegram推送](server/hooks/telegram_push/README.md)
|
||||
[垃圾邮件屏蔽](server/hooks/spam_block/README.md)
|
||||
|
||||
[WebHook推送](server/hooks/web_push/README.md)
|
||||
# 其他优秀开源插件
|
||||
|
||||
[Telegram推送](https://github.com/ydzydzydz/pmail_telegram_push)
|
||||
|
||||
## 插件安装
|
||||
> [!IMPORTANT]
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
## How To Ues
|
||||
|
||||
Create bot and get token from [BotFather](https://t.me/BotFather)
|
||||
|
||||
Copy plugin binary file to `/plugins`
|
||||
|
||||
add config.json to `/plugins/config.com` like this:
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"tgChatId": "", // telegram chatid
|
||||
"tgBotToken": "", // telegram token
|
||||
}
|
||||
|
||||
```
|
||||
@ -1,166 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"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"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type TelegramPushHook struct {
|
||||
chatId string
|
||||
botToken string
|
||||
httpsEnabled int
|
||||
webDomain string
|
||||
}
|
||||
|
||||
func (w *TelegramPushHook) ReceiveSaveAfter(ctx *context.Context, email *parsemail.Email, ue []*models.UserEmail) {
|
||||
if w.chatId == "" || w.botToken == "" {
|
||||
return
|
||||
}
|
||||
|
||||
for _, u := range ue {
|
||||
// 管理员(Uid=1)收到邮件且非已读、非已删除 触发通知
|
||||
if u.UserID == 1 && u.IsRead == 0 && u.Status == 0 && email.MessageId > 0 {
|
||||
w.sendUserMsg(nil, email)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
||||
}
|
||||
|
||||
func (w *TelegramPushHook) SendAfter(ctx *context.Context, email *parsemail.Email, err map[string]error) {
|
||||
|
||||
}
|
||||
|
||||
func (w *TelegramPushHook) ReceiveParseBefore(ctx *context.Context, email *[]byte) {
|
||||
|
||||
}
|
||||
|
||||
func (w *TelegramPushHook) ReceiveParseAfter(ctx *context.Context, email *parsemail.Email) {}
|
||||
|
||||
type SendMessageRequest struct {
|
||||
ChatID string `json:"chat_id"`
|
||||
Text string `json:"text"`
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup"`
|
||||
ParseMode string `json:"parse_mode"`
|
||||
}
|
||||
|
||||
type ReplyMarkup struct {
|
||||
InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
|
||||
}
|
||||
|
||||
type InlineKeyboardButton struct {
|
||||
Text string `json:"text"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
func (w *TelegramPushHook) sendUserMsg(ctx *context.Context, email *parsemail.Email) {
|
||||
url := w.webDomain
|
||||
if w.httpsEnabled > 1 {
|
||||
url = "http://" + url
|
||||
} else {
|
||||
url = "https://" + url
|
||||
}
|
||||
sendMsgReq, _ := json.Marshal(SendMessageRequest{
|
||||
ChatID: w.chatId,
|
||||
Text: fmt.Sprintf("📧<b>%s</b><%s>\n\n%s", email.Subject, email.From.EmailAddress, string(email.Text)),
|
||||
ParseMode: "HTML",
|
||||
ReplyMarkup: ReplyMarkup{
|
||||
InlineKeyboard: [][]InlineKeyboardButton{
|
||||
{
|
||||
{
|
||||
Text: "查收邮件",
|
||||
URL: url,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
_, err := http.Post(fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", w.botToken), "application/json", strings.NewReader(string(sendMsgReq)))
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Errorf("telegram push error %+v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
TgBotToken string `json:"tgBotToken"`
|
||||
TgChatId string `json:"tgChatId"`
|
||||
}
|
||||
|
||||
func NewTelegramPushHook() *TelegramPushHook {
|
||||
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/telegram_push_config.json"); err == nil {
|
||||
cfgData, err = os.ReadFile("./plugins/telegram_push_config.json")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = json.Unmarshal(cfgData, &pluginConfig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
token := ""
|
||||
chatID := ""
|
||||
if pluginConfig != nil {
|
||||
token = pluginConfig.TgBotToken
|
||||
chatID = pluginConfig.TgChatId
|
||||
} else {
|
||||
token = mainConfig.TgBotToken
|
||||
chatID = mainConfig.TgChatId
|
||||
}
|
||||
|
||||
ret := &TelegramPushHook{
|
||||
botToken: token,
|
||||
chatId: chatID,
|
||||
webDomain: mainConfig.WebDomain,
|
||||
httpsEnabled: mainConfig.HttpsEnabled,
|
||||
}
|
||||
return ret
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
framework.CreatePlugin("telegram_push", NewTelegramPushHook()).Run()
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user