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.
|
|
|
|
|
|
|
|
NetGuard is distributed in the hope that it will be useful,
|
|
|
|
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
|
|
|
|
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
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;
|
|
|
|
import androidx.room.PrimaryKey;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
|
|
|
@Entity(
|
|
|
|
tableName = EntityAccount.TABLE_NAME,
|
|
|
|
indices = {
|
|
|
|
}
|
|
|
|
)
|
|
|
|
public class EntityAccount {
|
|
|
|
static final String TABLE_NAME = "account";
|
|
|
|
|
|
|
|
@PrimaryKey(autoGenerate = true)
|
|
|
|
public Long id;
|
|
|
|
public String name;
|
2018-09-07 08:44:48 +00:00
|
|
|
public String signature;
|
2018-08-02 13:33:06 +00:00
|
|
|
@NonNull
|
|
|
|
public String host; // IMAP
|
|
|
|
@NonNull
|
|
|
|
public Integer port;
|
|
|
|
@NonNull
|
|
|
|
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 synchronize;
|
2018-10-07 06:53:09 +00:00
|
|
|
@NonNull
|
|
|
|
public Boolean primary;
|
2018-09-12 16:54:48 +00:00
|
|
|
public Integer color;
|
2018-08-21 16:32:10 +00:00
|
|
|
@NonNull
|
2018-08-25 14:24:26 +00:00
|
|
|
public Boolean store_sent; // obsolete
|
2018-08-23 09:48:27 +00:00
|
|
|
@NonNull
|
2018-10-07 06:53:09 +00:00
|
|
|
public Integer poll_interval; // keep-alive interval
|
2018-08-07 18:31:14 +00:00
|
|
|
public Long seen_until;
|
2018-08-13 14:44:47 +00:00
|
|
|
public String state;
|
2018-08-11 08:28:54 +00:00
|
|
|
public String error;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (obj instanceof EntityAccount) {
|
|
|
|
EntityAccount other = (EntityAccount) obj;
|
2018-08-04 19:54:33 +00:00
|
|
|
return ((this.name == null ? other.name == null : this.name.equals(other.name)) &&
|
2018-10-07 06:53:09 +00:00
|
|
|
(this.signature == null ? other.signature == null : this.signature.equals(other.signature)) &&
|
2018-08-02 13:33:06 +00:00
|
|
|
this.host.equals(other.host) &&
|
|
|
|
this.port.equals(other.port) &&
|
|
|
|
this.user.equals(other.user) &&
|
|
|
|
this.password.equals(other.password) &&
|
2018-10-07 06:53:09 +00:00
|
|
|
this.auth_type.equals(other.auth_type) &&
|
2018-08-11 08:28:54 +00:00
|
|
|
this.synchronize.equals(other.synchronize) &&
|
2018-10-07 06:53:09 +00:00
|
|
|
this.primary.equals(other.primary) &&
|
|
|
|
(this.color == null ? other.color == null : this.color.equals(other.color)) &&
|
2018-08-25 14:24:26 +00:00
|
|
|
this.poll_interval.equals(other.poll_interval) &&
|
2018-08-15 11:26:59 +00:00
|
|
|
(this.seen_until == null ? other.seen_until == null : this.seen_until.equals(other.seen_until)) &&
|
2018-08-13 14:44:47 +00:00
|
|
|
(this.state == null ? other.state == null : this.state.equals(other.state)) &&
|
2018-08-11 08:28:54 +00:00
|
|
|
(this.error == null ? other.error == null : this.error.equals(other.error)));
|
2018-08-02 13:33:06 +00:00
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-08 10:22:12 +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("signature", signature);
|
|
|
|
json.put("host", host);
|
|
|
|
json.put("port", port);
|
|
|
|
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);
|
2018-09-26 11:56:08 +00:00
|
|
|
json.put("synchronize", false);
|
2018-10-07 08:08:01 +00:00
|
|
|
json.put("primary", primary);
|
2018-09-14 11:33:22 +00:00
|
|
|
if (color != null)
|
|
|
|
json.put("color", color);
|
|
|
|
json.put("poll_interval", poll_interval);
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static EntityAccount fromJSON(JSONObject json) throws JSONException {
|
|
|
|
EntityAccount account = new EntityAccount();
|
|
|
|
if (json.has("name"))
|
|
|
|
account.name = json.getString("name");
|
|
|
|
if (json.has("signature"))
|
|
|
|
account.signature = json.getString("signature");
|
|
|
|
account.host = json.getString("host");
|
|
|
|
account.port = json.getInt("port");
|
|
|
|
account.user = json.getString("user");
|
|
|
|
account.password = json.getString("password");
|
|
|
|
account.auth_type = json.getInt("auth_type");
|
|
|
|
account.synchronize = json.getBoolean("synchronize");
|
2018-10-07 08:08:01 +00:00
|
|
|
account.primary = json.getBoolean("primary");
|
2018-09-14 11:33:22 +00:00
|
|
|
if (json.has("color"))
|
|
|
|
account.color = json.getInt("color");
|
|
|
|
account.poll_interval = json.getInt("poll_interval");
|
|
|
|
return account;
|
|
|
|
}
|
|
|
|
|
2018-08-08 10:22:12 +00:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return name + (primary ? " ★" : "");
|
|
|
|
}
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|