1 package org.cacert.gigi.api;
3 import java.io.IOException;
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
9 import org.cacert.gigi.GigiApiException;
10 import org.cacert.gigi.dbObjects.EmailAddress;
11 import org.cacert.gigi.dbObjects.User;
12 import org.json.JSONWriter;
14 public class Emails extends APIPoint {
16 public static final String PATH = "/account/emails";
19 public void processGet(HttpServletRequest req, HttpServletResponse resp, User u) throws IOException {
20 EmailAddress[] mails = u.getEmails();
21 resp.setContentType("application/json; charset=UTF-8");
22 JSONWriter jw = new JSONWriter(resp.getWriter());
24 for (EmailAddress emailAddress : mails) {
25 Date p = emailAddress.getLastPing(true);
28 jw.value(emailAddress.getId());
30 jw.value((p == null ? 0 : p.getTime()));
32 jw.value(emailAddress.getAddress());
39 protected void process(HttpServletRequest req, HttpServletResponse resp, User u) throws IOException {
41 String email = req.getParameter("email");
43 resp.sendError(500, "No parameter 'email'.");
46 new EmailAddress(u, email, u.getPreferredLocale());
47 } catch (IllegalArgumentException e) {
48 resp.sendError(500, "Invalid email");
49 } catch (GigiApiException e) {
51 resp.setContentType("text/plain; charset=UTF-8");
52 e.formatPlain(resp.getWriter());