This repository has been archived by the owner on May 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdelete.go
74 lines (65 loc) · 1.97 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
70
71
72
73
74
package disguise
import (
"fmt"
"google.golang.org/appengine"
"google.golang.org/appengine/datastore"
"google.golang.org/appengine/log"
"net/http"
"strconv"
)
// Delete handles delete requests of mail.
func Delete(w http.ResponseWriter, r *http.Request, mailInterval int) {
ctx := appengine.NewContext(r)
// The original MySQL query specified to order by ascending.
// Cloud Datastore seems to do this by default.
r.ParseForm()
delnum, err := strconv.Atoi(r.Form.Get("delnum"))
if err != nil {
fmt.Fprint(w, GenNormalErrorCode(ctx, 610, "delnum is invalid."))
return
}
passwd := r.Form.Get("passwd")
if passwd == "" || len(passwd) != 16 {
fmt.Fprintf(w, GenNormalErrorCode(ctx, 330, "Unable to parse parameters."))
return
}
// Check passwd
query := datastore.NewQuery("Accounts").Filter("Passwd = ", passwd).Limit(1)
for mlidResult := query.Run(ctx); ; {
var currentUser Accounts
mlidKey, err := mlidResult.Next(¤tUser)
if err == datastore.Done {
break
}
query := datastore.NewQuery("Mail").
Filter("Delivered = ", true).
// Remove w from friend code
Filter("RecipientID = ", mlidKey.StringID()).
Limit(delnum)
for mailToDelete := query.Run(ctx); ; {
var currentMail Mail
mailKey, err := mailToDelete.Next(¤tMail)
if err == datastore.Done {
break
}
if err != nil {
log.Warningf(ctx, "Couldn't cycle through mail! %v", err)
fmt.Fprintf(w, GenNormalErrorCode(ctx, 541, "Issue deleting mail from the database."))
return
}
// delet this
if datastore.Delete(ctx, mailKey) != nil {
log.Errorf(ctx, "Couldn't delete mail from database!")
fmt.Fprintf(w, GenNormalErrorCode(ctx, 541, "Issue deleting mail from the database."))
return
}
}
fmt.Fprint(w, GenNormalErrorCode(ctx, 100, "Success."),
"deletenum=", delnum,
"rcv.interval=", mailInterval)
return
}
// Only runs if not returned from earlier.
fmt.Fprintf(w, GenNormalErrorCode(ctx, 220, "Invalid authentication."))
return
}