Files
FairEmail/app/src/main/java/eu/faircode/email/EntityIdentity.java

141 lines
4.7 KiB
Java
Raw Normal View History

2018-08-02 13:33:06 +00:00
package eu.faircode.email;
/*
2018-08-14 05:53:24 +00:00
This file is part of FairEmail.
2018-08-02 13:33:06 +00:00
2018-08-14 05:53:24 +00:00
FairEmail is free software: you can redistribute it and/or modify
2018-08-02 13:33:06 +00:00
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2018-10-29 10:46:49 +00:00
FairEmail is distributed in the hope that it will be useful,
2018-08-02 13:33:06 +00:00
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
2018-10-29 10:46:49 +00:00
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2018-08-02 13:33:06 +00:00
Copyright 2018 by Marcel Bokhorst (M66B)
*/
2018-09-14 11:33:22 +00:00
import org.json.JSONException;
import org.json.JSONObject;
2018-08-08 06:55:47 +00:00
import androidx.annotation.NonNull;
import androidx.room.Entity;
2018-08-08 10:22:12 +00:00
import androidx.room.ForeignKey;
import androidx.room.Index;
2018-08-08 06:55:47 +00:00
import androidx.room.PrimaryKey;
2018-08-02 13:33:06 +00:00
2018-08-08 10:22:12 +00:00
import static androidx.room.ForeignKey.CASCADE;
2018-08-02 13:33:06 +00:00
@Entity(
tableName = EntityIdentity.TABLE_NAME,
2018-08-08 10:22:12 +00:00
foreignKeys = {
@ForeignKey(childColumns = "account", entity = EntityAccount.class, parentColumns = "id", onDelete = CASCADE)
},
2018-08-02 13:33:06 +00:00
indices = {
2018-08-08 10:22:12 +00:00
@Index(value = {"account"})
2018-08-02 13:33:06 +00:00
}
)
public class EntityIdentity {
static final String TABLE_NAME = "identity";
@PrimaryKey(autoGenerate = true)
public Long id;
@NonNull
public String name;
@NonNull
public String email;
public String replyto;
@NonNull
2018-08-08 10:22:12 +00:00
public Long account;
@NonNull
2018-08-02 13:33:06 +00:00
public String host; // SMTP
@NonNull
public Boolean starttls;
@NonNull
2018-10-23 07:52:20 +00:00
public Boolean insecure;
@NonNull
public Integer port;
@NonNull
2018-08-02 13:33:06 +00:00
public String user;
@NonNull
public String password;
@NonNull
2018-08-27 14:31:45 +00:00
public Integer auth_type;
@NonNull
2018-08-02 13:33:06 +00:00
public Boolean primary;
@NonNull
public Boolean synchronize;
2018-08-25 14:24:26 +00:00
@NonNull
public Boolean store_sent;
2018-08-15 11:26:59 +00:00
public String state;
public String error;
2018-08-02 13:33:06 +00:00
2018-09-14 11:33:22 +00:00
public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject();
json.put("name", name);
json.put("email", email);
json.put("replyto", replyto);
json.put("host", host);
json.put("port", port);
json.put("starttls", starttls);
2018-10-24 11:14:56 +00:00
json.put("insecure", insecure);
2018-09-14 11:33:22 +00:00
json.put("user", user);
2018-09-20 17:25:41 +00:00
json.put("password", "");
2018-09-14 11:33:22 +00:00
json.put("auth_type", auth_type);
json.put("primary", primary);
2018-09-26 11:56:08 +00:00
json.put("synchronize", false);
2018-09-14 11:33:22 +00:00
json.put("store_sent", store_sent);
return json;
}
public static EntityIdentity fromJSON(JSONObject json) throws JSONException {
EntityIdentity identity = new EntityIdentity();
identity.name = json.getString("name");
identity.email = json.getString("email");
if (json.has("replyto"))
identity.replyto = json.getString("replyto");
identity.host = json.getString("host");
identity.port = json.getInt("port");
identity.starttls = json.getBoolean("starttls");
2018-10-24 11:14:56 +00:00
identity.insecure = (json.has("insecure") && json.getBoolean("insecure"));
2018-09-14 11:33:22 +00:00
identity.user = json.getString("user");
identity.password = json.getString("password");
identity.auth_type = json.getInt("auth_type");
identity.primary = json.getBoolean("primary");
identity.synchronize = json.getBoolean("synchronize");
identity.store_sent = json.getBoolean("store_sent");
return identity;
}
2018-08-02 13:33:06 +00:00
@Override
public boolean equals(Object obj) {
if (obj instanceof EntityIdentity) {
EntityIdentity other = (EntityIdentity) obj;
return (this.name.equals(other.name) &&
this.email.equals(other.email) &&
2018-08-04 19:54:33 +00:00
(this.replyto == null ? other.replyto == null : this.replyto.equals(other.replyto)) &&
2018-08-08 10:22:12 +00:00
this.account.equals(other.account) &&
2018-08-02 13:33:06 +00:00
this.host.equals(other.host) &&
this.port.equals(other.port) &&
this.starttls.equals(other.starttls) &&
this.user.equals(other.user) &&
this.password.equals(other.password) &&
this.primary.equals(other.primary) &&
2018-08-15 11:26:59 +00:00
this.synchronize.equals(other.synchronize) &&
2018-08-25 14:24:26 +00:00
this.store_sent.equals(other.store_sent) &&
2018-08-15 11:26:59 +00:00
(this.state == null ? other.state == null : this.state.equals(other.state)) &&
(this.error == null ? other.error == null : this.error.equals(other.error)));
2018-08-02 13:33:06 +00:00
} else
return false;
}
@Override
public String toString() {
2018-08-06 09:50:53 +00:00
return name + (primary ? "" : "");
2018-08-02 13:33:06 +00:00
}
}