commit f4dc4985003737550d70f56d782cecc2c0e3b192 from: Oliver Lowe date: Mon Apr 25 03:40:27 2022 UTC mailmux, docs: serialise time as RFC3339, not Unix this is what Go's time package expects when marshalling time in JSON. commit - be20893f819a5320fcf7aae0fd66f48c2e1651ed commit + f4dc4985003737550d70f56d782cecc2c0e3b192 blob - 5af8e3e5a81c2cd5ecd88534cf731e7c5465055b blob + bb132cc62006889ebd5ab1628839011082345374 --- docs/httpapiref.md +++ docs/httpapiref.md @@ -78,7 +78,7 @@ Any mail addressed to the recipient of the alias will { "Recipient": "wondering_underbelly71", "Destination": "test@example.com", - "Expiry": 1845067777, + "Expiry": "2006-01-02T15:04:05Z07:00", "Note": "newsletters for example.org" } ``` @@ -93,8 +93,8 @@ implementation.
Destination string
Destination contains an email address, with domain suffix, to which mail will be forwarded.
-
Expiry integer
-
Expiry specifies a time in seconds since the UNIX epoch +
Expiry string
+
Expiry specifies a time in RFC3339 format after which the alias is considered inactive; that is, mail addressed to Recipient should be bounced.
Note string
@@ -112,7 +112,7 @@ POST /v1/aliases { "Recipient": "wondering_underbelly71", "Destination": "test@example.com", - "Expiry": 1845067777, + "Expiry": "2006-01-02T15:04:05Z07:00", "Note": "newsletters for example.org" } ``` @@ -124,12 +124,12 @@ Otherwise, an error is returned. ### Parameters
-
Expiry optional integer
-
Expiry specifies a time in seconds since the UNIX epoch +
expiry optional string
+
Expiry specifies a time in RFC3339 format after which the alias is considered inactive; that is, mail addressed to Recipient should be bounced. By default, aliases never expire.
-
Note optional string
+
note optional string
Note contains user-defined text that can be used to, for example, identify the alias. By default, aliases have no note.
@@ -144,7 +144,7 @@ GET /v1/aliases/:recipient { "Recipient": "wondering_underbelly71", "Destination": "test@example.com", - "Expiry": 1845067777, + "Expiry": "2006-01-02T15:04:05Z07:00", "Note": "newsletters for example.org" } ``` @@ -166,13 +166,13 @@ GET /v1/aliases { "Recipient": "wondering_underbelly71", "Destination": "test@example.com", - "Expiry": 1845067777, + "Expiry": "2006-01-02T15:04:05Z07:00", "Note": "newsletters for example.org" }, { "Recipient": "humble_anteater48", "Destination": "test@example.com", - "Expiry": 1845067777, + "Expiry": "2006-01-02T15:04:05Z07:00", "Note": "supermarket rewards card" } ] @@ -198,8 +198,8 @@ To unset parameters, set their values to the empty str This can be used to, for example, remove an alias' expiry time.
-
Expiry optional integer
-
Expiry specifies a time in seconds since the UNIX epoch +
expiry optional string
+
Expiry specifies a time in RFC3339 format after which the alias is considered inactive; that is, mail addressed to Recipient should be bounced. By default, aliases never expire.
blob - 0b890f911e3eba88a8ed52c81ccfa8deb4b7489d blob + 6900c57608e3939ff6ad832989e9042986ddf98b --- http.go +++ http.go @@ -6,7 +6,6 @@ import ( "fmt" "net/http" "path" - "strconv" "strings" "time" ) @@ -114,16 +113,15 @@ func (h *aliasHandler) ServeHTTP(w http.ResponseWriter for param := range req.PostForm { switch param { case "expiry": - i, err := strconv.Atoi(req.PostForm.Get(param)) + alias.Expiry, err = time.Parse(time.RFC3339, req.PostForm.Get(param)) if err != nil { jerror(w, fmt.Sprintf("parse expiry: %v", err), http.StatusBadRequest) return } - alias.Expiry = time.Unix(int64(i), 0) case "note": alias.Note = req.PostForm.Get(param) default: - jerror(w, fmt.Sprintf("invalid alias parameter %s", param), http.StatusBadRequest) + jerror(w, fmt.Sprintf("bad alias parameter %s", param), http.StatusBadRequest) return } } @@ -134,7 +132,8 @@ func (h *aliasHandler) ServeHTTP(w http.ResponseWriter json.NewEncoder(w).Encode(alias) default: - jerror(w, "not implemented yet", http.StatusMethodNotAllowed) + code := http.StatusMethodNotAllowed + jerror(w, http.StatusText(code), code) } }