func EmailItems(w http.ResponseWriter, r *http.Request, dbCoords database.ConnCoordinates, opts ...interface{}) {
	db, err := database.InitializeDB(dbCoords)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	defer db.Close()
	apiHost, apiHostOk := opts[0].(string)
	if !apiHostOk {
		http.Error(w, BAD_REQUEST, http.StatusInternalServerError)
		return
	}
	acc, accErr := database.GetDesignatedAccount(db)
	if accErr != nil {
		http.Error(w, accErr.Error(), http.StatusInternalServerError)
		return
	}
	if "POST" == r.Method {
		r.ParseForm()
		accVal, accExists := r.PostForm["account"]
		items, itemsExist := r.PostForm["item"]
		if itemsExist && accExists {
			if len(accVal) > 0 {
				id, idErr := strconv.ParseInt(accVal[0], 10, 64)
				if idErr != nil {
					http.Error(w, idErr.Error(), http.StatusInternalServerError)
					return
				} else {
					if acc.Id != id {
						http.Error(w, BAD_REQUEST, http.StatusInternalServerError)
						return
					} else {
						if acc.Email != database.ANONYMOUS_EMAIL {
							accountItems, accountItemsErr := database.GetItems(db, acc)
							if accountItemsErr == nil {
								ping := func() {
									v := url.Values{}
									v.Set("email", acc.Email)
									for _, accItem := range accountItems {
										for _, item := range items {
											if strconv.FormatInt(accItem.Id, 10) == item {
												v.Add("item", accItem.Desc)
												break
											}
										}
									}
									hmac := digest.GenerateDigest(acc.APICode, v.Encode())
									v.Set("hmac", hmac)
									res, err := http.PostForm(strings.Join([]string{apiHost, "/email/"}, ""), v)
									if err == nil {
										res.Body.Close()
									}
								}
								go ping()  
							}
						}
					}
				}
			} else {
				http.Error(w, "Missing account id", http.StatusInternalServerError)
				return
			}
		} else {
			http.Error(w, BAD_POST, http.StatusInternalServerError)
			return
		}
	} else {
		http.Error(w, BAD_REQUEST, http.StatusInternalServerError)
		return
	}
	http.Redirect(w, r, HOME_URL+"?ack=email", http.StatusFound)
}
EmailItems handles the client form post, to send a list of the selected
items via email to the given user
package ui
import (
	"github.com/Banrai/PiScan/client/database"
	"github.com/Banrai/PiScan/server/digest"
	"net/http"
	"net/url"
	"strconv"
	"strings"
)