-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete.go
69 lines (60 loc) · 1.59 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"errors"
"github.com/gin-gonic/gin"
"net/http"
"strconv"
)
const DeleteSentMail = `DELETE FROM mail WHERE is_sent = true AND recipient = $1`
func _delete(c *gin.Context) {
mlid := c.PostForm("mlid")
password := c.PostForm("passwd")
ctx := c.Copy()
err := validatePassword(ctx, mlid, password)
if errors.Is(err, ErrInvalidCredentials) {
cgi := GenCGIError(250, err.Error())
ReportError(err)
c.String(http.StatusOK, ConvertToCGI(cgi))
return
} else if err != nil {
cgi := GenCGIError(551, "An error has occurred while querying the database.")
ReportError(err)
c.String(http.StatusOK, ConvertToCGI(cgi))
return
}
// We are sent the number of messages to delete, however we will ignore it as
// we set a flag for the messages that were already sent.
delNum := c.PostForm("delnum")
// Integer checking
intDelNum, err := strconv.ParseInt(delNum, 10, 64)
if err != nil {
cgi := GenCGIError(340, "Invalid delnum value was passed")
ReportError(err)
c.String(http.StatusOK, ConvertToCGI(cgi))
return
}
_, err = pool.Exec(ctx, DeleteSentMail, mlid[1:])
if err != nil {
cgi := GenCGIError(541, "An error has occurred while deleting the messages from the database.")
ReportError(err)
c.String(http.StatusOK, ConvertToCGI(cgi))
return
}
cgi := CGIResponse{
code: 100,
message: "Success.",
other: []KV{
{
key: "deletenum",
value: delNum,
},
},
}
if config.UseDatadog {
err = dataDog.Incr("mail.deleted_mail", nil, float64(intDelNum))
if err != nil {
ReportError(err)
}
}
c.String(http.StatusOK, ConvertToCGI(cgi))
}