]> WPIA git - gigi.git/commitdiff
FIX: Additional check before maildeletion
authorJanis Streib <janis@dogcraft.de>
Sat, 26 Jul 2014 20:49:34 +0000 (22:49 +0200)
committerJanis Streib <janis@dogcraft.de>
Sat, 26 Jul 2014 20:54:29 +0000 (22:54 +0200)
src/org/cacert/gigi/User.java

index 4cf318228bf311e679aa4b21840d8031bf92e89b..010df4a9773cd48ee705d79d4a50c0f6491c16f8 100644 (file)
@@ -321,14 +321,22 @@ public class User {
                if (getEmail().equals(mail.getAddress())) {
                        throw new GigiApiException("Can't delete user's default e-mail.");
                }
                if (getEmail().equals(mail.getAddress())) {
                        throw new GigiApiException("Can't delete user's default e-mail.");
                }
-               try {
-                       PreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE email SET deleted=? WHERE id=?");
-                       ps.setDate(1, new Date(System.currentTimeMillis()));
-                       ps.setInt(2, mail.getId());
-                       ps.execute();
-               } catch (SQLException e) {
-                       e.printStackTrace();
-                       throw new GigiApiException(e);
+               EmailAddress[] emails = getEmails();
+               for (int i = 0; i < emails.length; i++) {
+                       if (emails[i].getId() == mail.getId()) {
+                               try {
+                                       PreparedStatement ps = DatabaseConnection.getInstance().prepare(
+                                               "UPDATE email SET deleted=? WHERE id=?");
+                                       ps.setDate(1, new Date(System.currentTimeMillis()));
+                                       ps.setInt(2, mail.getId());
+                                       ps.execute();
+                               } catch (SQLException e) {
+                                       e.printStackTrace();
+                                       throw new GigiApiException(e);
+                               }
+                               return;
+                       }
                }
                }
+               throw new GigiApiException("Email not one user's mail addresses.");
        }
 }
        }
 }