Add option to specify a particular IMAP folder (aka "label" in Gmail) (#477)

This commit is contained in:
Evil McJerkface 2020-11-22 06:39:39 -06:00 committed by GitHub
parent b6ec5e108b
commit 1346dd3616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 42 additions and 6 deletions

View File

@ -42,6 +42,7 @@ public enum ConfigType {
INBOX_PORT, INBOX_PORT,
INBOX_USERNAME, INBOX_USERNAME,
INBOX_PASSWORD, INBOX_PASSWORD,
INBOX_FOLDER,
INBOX_TAG, INBOX_TAG,
INBOX_AUTOMATIC_TAGS, INBOX_AUTOMATIC_TAGS,
INBOX_DELETE_IMPORTED, INBOX_DELETE_IMPORTED,

View File

@ -97,7 +97,7 @@ public class InboxService extends AbstractScheduledService {
} catch (FolderClosedException e) { } catch (FolderClosedException e) {
// Ignore this, we will just continue importing on the next cycle // Ignore this, we will just continue importing on the next cycle
} catch (Exception e) { } catch (Exception e) {
log.error("Error synching the inbox", e); log.error("Error syncing the inbox", e);
lastSyncError = e.getMessage(); lastSyncError = e.getMessage();
} finally { } finally {
try { try {
@ -181,7 +181,7 @@ public class InboxService extends AbstractScheduledService {
store.connect(ConfigUtil.getConfigStringValue(ConfigType.INBOX_USERNAME), store.connect(ConfigUtil.getConfigStringValue(ConfigType.INBOX_USERNAME),
ConfigUtil.getConfigStringValue(ConfigType.INBOX_PASSWORD)); ConfigUtil.getConfigStringValue(ConfigType.INBOX_PASSWORD));
Folder inbox = store.getFolder("INBOX"); Folder inbox = store.getFolder(ConfigUtil.getConfigStringValue(ConfigType.INBOX_FOLDER));
inbox.open(Folder.READ_WRITE); inbox.open(Folder.READ_WRITE);
return inbox; return inbox;
} }

View File

@ -1 +1 @@
db.version=26 db.version=27

View File

@ -0,0 +1,2 @@
insert into T_CONFIG(CFG_ID_C, CFG_VALUE_C) values('INBOX_FOLDER', 'INBOX');
update T_CONFIG set CFG_VALUE_C = '27' where CFG_ID_C = 'DB_VERSION';

View File

@ -1,3 +1,3 @@
api.current_version=${project.version} api.current_version=${project.version}
api.min_version=1.0 api.min_version=1.0
db.version=26 db.version=27

View File

@ -312,6 +312,7 @@ public class AppResource extends BaseResource {
* @apiSuccess {String} port IMAP port * @apiSuccess {String} port IMAP port
* @apiSuccess {String} username IMAP username * @apiSuccess {String} username IMAP username
* @apiSuccess {String} password IMAP password * @apiSuccess {String} password IMAP password
* @apiSuccess {String} folder IMAP folder
* @apiSuccess {String} tag Tag for created documents * @apiSuccess {String} tag Tag for created documents
* @apiError (client) ForbiddenError Access denied * @apiError (client) ForbiddenError Access denied
* @apiPermission admin * @apiPermission admin
@ -335,6 +336,7 @@ public class AppResource extends BaseResource {
Config portConfig = configDao.getById(ConfigType.INBOX_PORT); Config portConfig = configDao.getById(ConfigType.INBOX_PORT);
Config usernameConfig = configDao.getById(ConfigType.INBOX_USERNAME); Config usernameConfig = configDao.getById(ConfigType.INBOX_USERNAME);
Config passwordConfig = configDao.getById(ConfigType.INBOX_PASSWORD); Config passwordConfig = configDao.getById(ConfigType.INBOX_PASSWORD);
Config folderConfig = configDao.getById(ConfigType.INBOX_FOLDER);
Config tagConfig = configDao.getById(ConfigType.INBOX_TAG); Config tagConfig = configDao.getById(ConfigType.INBOX_TAG);
JsonObjectBuilder response = Json.createObjectBuilder(); JsonObjectBuilder response = Json.createObjectBuilder();
@ -361,6 +363,11 @@ public class AppResource extends BaseResource {
} else { } else {
response.add("password", passwordConfig.getValue()); response.add("password", passwordConfig.getValue());
} }
if (folderConfig == null) {
response.addNull("folder");
} else {
response.add("folder", folderConfig.getValue());
}
if (tagConfig == null) { if (tagConfig == null) {
response.addNull("tag"); response.addNull("tag");
} else { } else {
@ -393,6 +400,7 @@ public class AppResource extends BaseResource {
* @apiParam {Integer} port IMAP port * @apiParam {Integer} port IMAP port
* @apiParam {String} username IMAP username * @apiParam {String} username IMAP username
* @apiParam {String} password IMAP password * @apiParam {String} password IMAP password
* @apiParam {String} folder IMAP folder
* @apiParam {String} tag Tag for created documents * @apiParam {String} tag Tag for created documents
* @apiError (client) ForbiddenError Access denied * @apiError (client) ForbiddenError Access denied
* @apiError (client) ValidationError Validation error * @apiError (client) ValidationError Validation error
@ -404,6 +412,7 @@ public class AppResource extends BaseResource {
* @param portStr IMAP port * @param portStr IMAP port
* @param username IMAP username * @param username IMAP username
* @param password IMAP password * @param password IMAP password
* @param folder IMAP folder
* @param tag Tag for created documents * @param tag Tag for created documents
* @return Response * @return Response
*/ */
@ -416,6 +425,7 @@ public class AppResource extends BaseResource {
@FormParam("port") String portStr, @FormParam("port") String portStr,
@FormParam("username") String username, @FormParam("username") String username,
@FormParam("password") String password, @FormParam("password") String password,
@FormParam("folder") String folder,
@FormParam("tag") String tag) { @FormParam("tag") String tag) {
if (!authenticate()) { if (!authenticate()) {
throw new ForbiddenClientException(); throw new ForbiddenClientException();
@ -443,6 +453,9 @@ public class AppResource extends BaseResource {
if (!Strings.isNullOrEmpty(password)) { if (!Strings.isNullOrEmpty(password)) {
configDao.update(ConfigType.INBOX_PASSWORD, password); configDao.update(ConfigType.INBOX_PASSWORD, password);
} }
if (!Strings.isNullOrEmpty(folder)) {
configDao.update(ConfigType.INBOX_FOLDER, folder);
}
if (!Strings.isNullOrEmpty(tag)) { if (!Strings.isNullOrEmpty(tag)) {
configDao.update(ConfigType.INBOX_TAG, tag); configDao.update(ConfigType.INBOX_TAG, tag);
} }

View File

@ -427,6 +427,7 @@
"port": "IMAP Port (143 oder 993)", "port": "IMAP Port (143 oder 993)",
"username": "IMAP Benutzername", "username": "IMAP Benutzername",
"password": "IMAP Passwort", "password": "IMAP Passwort",
"folder": "IMAP Ordner",
"tag": "Folgenden Tag zu importierten Dokumenten hinzufügen", "tag": "Folgenden Tag zu importierten Dokumenten hinzufügen",
"test": "Konfiguration testen", "test": "Konfiguration testen",
"last_sync": "Letzte Synchronisation: {{ data.date | date: 'medium' }}, {{ data.count }} E-Mail(s){{ data.count > 1 ? 's' : '' }} importiert", "last_sync": "Letzte Synchronisation: {{ data.date | date: 'medium' }}, {{ data.count }} E-Mail(s){{ data.count > 1 ? 's' : '' }} importiert",

View File

@ -441,6 +441,7 @@
"port": "IMAP θύρα (143 ή 993)", "port": "IMAP θύρα (143 ή 993)",
"username": "IMAP όνομα χρήστη", "username": "IMAP όνομα χρήστη",
"password": "IMAP κωδικός", "password": "IMAP κωδικός",
"folder": "IMAP φάκελο",
"tag": "Ετικέτα που προστέθηκε σε ειχερχόμενα έγγραφα", "tag": "Ετικέτα που προστέθηκε σε ειχερχόμενα έγγραφα",
"test": "Δοκιμή μαραμέτρων", "test": "Δοκιμή μαραμέτρων",
"last_sync": "Τελευταίος συγχρονισμός: {{ data.date | date: 'medium' }}, {{ data.count }} μήνυμα εισήχθη", "last_sync": "Τελευταίος συγχρονισμός: {{ data.date | date: 'medium' }}, {{ data.count }} μήνυμα εισήχθη",

View File

@ -441,6 +441,7 @@
"port": "IMAP port (143 or 993)", "port": "IMAP port (143 or 993)",
"username": "IMAP username", "username": "IMAP username",
"password": "IMAP password", "password": "IMAP password",
"folder": "IMAP folder",
"tag": "Tag added to imported documents", "tag": "Tag added to imported documents",
"test": "Test the parameters", "test": "Test the parameters",
"last_sync": "Last synchronization: {{ data.date | date: 'medium' }}, {{ data.count }} message{{ data.count > 1 ? 's' : '' }} imported", "last_sync": "Last synchronization: {{ data.date | date: 'medium' }}, {{ data.count }} message{{ data.count > 1 ? 's' : '' }} imported",

View File

@ -416,6 +416,7 @@
"port": "Puerto IMAP (143 o 993)", "port": "Puerto IMAP (143 o 993)",
"username": "Usuario IMAP", "username": "Usuario IMAP",
"password": "Contraseña IMAP", "password": "Contraseña IMAP",
"folder": "Carpeta IMAP",
"tag": "Etiqueta añadida a documentos importado", "tag": "Etiqueta añadida a documentos importado",
"test": "Comprobar parámetros", "test": "Comprobar parámetros",
"last_sync": "Última sincronización: {{ data.date | date: 'medium' }}, {{ data.count }} mensaje{{ data.count > 1 ? 's' : '' }} importado{{ data.count > 1 ? 's' : '' }}", "last_sync": "Última sincronización: {{ data.date | date: 'medium' }}, {{ data.count }} mensaje{{ data.count > 1 ? 's' : '' }} importado{{ data.count > 1 ? 's' : '' }}",

View File

@ -430,6 +430,7 @@
"port": "Port IMAP (143 ou 993)", "port": "Port IMAP (143 ou 993)",
"username": "Nom d'utilisateur IMAP", "username": "Nom d'utilisateur IMAP",
"password": "Mot de passe IMAP", "password": "Mot de passe IMAP",
"folder": "Dossier IMAP",
"tag": "Tag ajouté aux documents importés", "tag": "Tag ajouté aux documents importés",
"test": "Tester les paramètres", "test": "Tester les paramètres",
"last_sync": "Dernière synchronisation : {{ data.date | date: 'medium' }}, {{ data.count }} message{{ data.count> 1 ? 's' : '' }} importé{{ data.count> 1 ? 's' : '' }}", "last_sync": "Dernière synchronisation : {{ data.date | date: 'medium' }}, {{ data.count }} message{{ data.count> 1 ? 's' : '' }} importé{{ data.count> 1 ? 's' : '' }}",

View File

@ -441,6 +441,7 @@
"port": "Porta IMAP (143 o 993)", "port": "Porta IMAP (143 o 993)",
"username": "Nome utente IMAP", "username": "Nome utente IMAP",
"password": "Password IMAP", "password": "Password IMAP",
"folder": "Cartella IMAP",
"tag": "Tag aggiunti a documenti importati", "tag": "Tag aggiunti a documenti importati",
"test": "Testa i parametri", "test": "Testa i parametri",
"last_sync": "Ultima sincronizzazione: {{ data.date | date: 'medium' }}, {{ data.count }} messaggi{{ data.count > 1 ? '' : 'o' }} importat{{ data.count > 1 ? 'i' : 'o' }}", "last_sync": "Ultima sincronizzazione: {{ data.date | date: 'medium' }}, {{ data.count }} messaggi{{ data.count > 1 ? '' : 'o' }} importat{{ data.count > 1 ? 'i' : 'o' }}",

View File

@ -441,6 +441,7 @@
"port": "Port IMAP (143 or 993)", "port": "Port IMAP (143 or 993)",
"username": "Użytkownik IMAP", "username": "Użytkownik IMAP",
"password": "Hasło IMAP", "password": "Hasło IMAP",
"folder": "Folderze IMAP",
"tag": "Etykieta dodawana do za zaimportowanych dokumentów", "tag": "Etykieta dodawana do za zaimportowanych dokumentów",
"test": "Przetestuj połączenie", "test": "Przetestuj połączenie",
"last_sync": "Ostatnia synchronizacja: {{ data.date | date: 'medium' }}, {{ data.count }} zaimportowano {{ data.count > 1 ? 's' : '' }} dokumentów", "last_sync": "Ostatnia synchronizacja: {{ data.date | date: 'medium' }}, {{ data.count }} zaimportowano {{ data.count > 1 ? 's' : '' }} dokumentów",

View File

@ -369,6 +369,7 @@
"port": "Порт IMAP (143 или 993)", "port": "Порт IMAP (143 или 993)",
"username": "Имя пользователя IMAP", "username": "Имя пользователя IMAP",
"password": "Пароль IMAP", "password": "Пароль IMAP",
"folder": "Папке IMAP",
"tag": "Тег добавлен в импортированные документы", "tag": "Тег добавлен в импортированные документы",
"test": "Проверить параметры", "test": "Проверить параметры",
"last_sync": "Последняя синхронизация: {{data.date | date}}, {{data.count}} импортировано", "last_sync": "Последняя синхронизация: {{data.date | date}}, {{data.count}} импортировано",

View File

@ -369,6 +369,7 @@
"port": "IMAP端口143或993", "port": "IMAP端口143或993",
"username": "IMAP用户名", "username": "IMAP用户名",
"password": "IMAP密码", "password": "IMAP密码",
"folder": "IMAP 件夹中",
"tag": "标签添加到导入的文档", "tag": "标签添加到导入的文档",
"test": "测试参数", "test": "测试参数",
"last_sync": "上次同步:{{ data.date | date }}{{ data.count }}消息导入", "last_sync": "上次同步:{{ data.date | date }}{{ data.count }}消息导入",

View File

@ -369,6 +369,7 @@
"port": "IMAP端口143或993", "port": "IMAP端口143或993",
"username": "IMAP用戶名", "username": "IMAP用戶名",
"password": "IMAP密碼", "password": "IMAP密碼",
"folder": "IMAP 資料夾",
"tag": "標籤添加到導入的文檔", "tag": "標籤添加到導入的文檔",
"test": "測試參數", "test": "測試參數",
"last_sync": "上次同步:{{ data.date | date }}{{data.count}}消息導入", "last_sync": "上次同步:{{ data.date | date }}{{data.count}}消息導入",

View File

@ -59,6 +59,13 @@
</div> </div>
</div> </div>
<div class="form-group">
<label class="col-sm-2 control-label" for="inboxFolder">{{ 'settings.inbox.folder' | translate }}</label>
<div class="col-sm-7">
<input name="folder" type="text" class="form-control" id="inboxFolder" ng-model="inbox.folder" />
</div>
</div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label" for="inboxTag">{{ 'settings.inbox.tag' | translate }}</label> <label class="col-sm-2 control-label" for="inboxTag">{{ 'settings.inbox.tag' | translate }}</label>
<div class="col-sm-7"> <div class="col-sm-7">

View File

@ -1,3 +1,3 @@
api.current_version=${project.version} api.current_version=${project.version}
api.min_version=1.0 api.min_version=1.0
db.version=26 db.version=27

View File

@ -1,3 +1,3 @@
api.current_version=${project.version} api.current_version=${project.version}
api.min_version=1.0 api.min_version=1.0
db.version=26 db.version=27

View File

@ -243,6 +243,7 @@ public class TestAppResource extends BaseJerseyTest {
Assert.assertEquals(993, json.getJsonNumber("port").intValue()); Assert.assertEquals(993, json.getJsonNumber("port").intValue());
Assert.assertEquals("", json.getString("username")); Assert.assertEquals("", json.getString("username"));
Assert.assertEquals("", json.getString("password")); Assert.assertEquals("", json.getString("password"));
Assert.assertEquals("INBOX", json.getString("folder"));
Assert.assertEquals("", json.getString("tag")); Assert.assertEquals("", json.getString("tag"));
JsonObject lastSync = json.getJsonObject("last_sync"); JsonObject lastSync = json.getJsonObject("last_sync");
Assert.assertTrue(lastSync.isNull("date")); Assert.assertTrue(lastSync.isNull("date"));
@ -260,6 +261,7 @@ public class TestAppResource extends BaseJerseyTest {
.param("port", "9755") .param("port", "9755")
.param("username", "test@sismics.com") .param("username", "test@sismics.com")
.param("password", "12345678") .param("password", "12345678")
.param("folder", "INBOX")
.param("tag", tagInboxId) .param("tag", tagInboxId)
), JsonObject.class); ), JsonObject.class);
@ -272,6 +274,7 @@ public class TestAppResource extends BaseJerseyTest {
Assert.assertEquals(9755, json.getInt("port")); Assert.assertEquals(9755, json.getInt("port"));
Assert.assertEquals("test@sismics.com", json.getString("username")); Assert.assertEquals("test@sismics.com", json.getString("username"));
Assert.assertEquals("12345678", json.getString("password")); Assert.assertEquals("12345678", json.getString("password"));
Assert.assertEquals("INBOX", json.getString("folder"));
Assert.assertEquals(tagInboxId, json.getString("tag")); Assert.assertEquals(tagInboxId, json.getString("tag"));
ServerSetup serverSetupSmtp = new ServerSetup(9754, null, ServerSetup.PROTOCOL_SMTP); ServerSetup serverSetupSmtp = new ServerSetup(9754, null, ServerSetup.PROTOCOL_SMTP);