Closes #632: validate POST /app/config_inbox and update documentation

This commit is contained in:
bgamard 2022-04-17 13:23:22 +02:00
parent bd23f14792
commit e6cfd899e5
2 changed files with 9 additions and 5 deletions

View File

@ -85,7 +85,7 @@ public class InboxService extends AbstractScheduledService {
lastSyncDate = new Date(); lastSyncDate = new Date();
lastSyncMessageCount = 0; lastSyncMessageCount = 0;
try { try {
HashMap<String, String> tagsNameToId = getAllTags(); Map<String, String> tagsNameToId = getAllTags();
inbox = openInbox(); inbox = openInbox();
Message[] messages = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false)); Message[] messages = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
@ -192,7 +192,7 @@ public class InboxService extends AbstractScheduledService {
* @param message Message * @param message Message
* @throws Exception e * @throws Exception e
*/ */
private void importMessage(Message message, HashMap<String, String> tags) throws Exception { private void importMessage(Message message, Map<String, String> tags) throws Exception {
log.info("Importing message: " + message.getSubject()); log.info("Importing message: " + message.getSubject());
// Parse the mail // Parse the mail
@ -273,16 +273,16 @@ public class InboxService extends AbstractScheduledService {
/** /**
* Fetches a HashMap with all tag names as keys and their respective ids as values. * Fetches a HashMap with all tag names as keys and their respective ids as values.
* *
* @return HashMap with all tags or null if not enabled * @return Map with all tags or null if not enabled
*/ */
private HashMap<String, String> getAllTags() { private Map<String, String> getAllTags() {
if (!ConfigUtil.getConfigBooleanValue(ConfigType.INBOX_AUTOMATIC_TAGS)) { if (!ConfigUtil.getConfigBooleanValue(ConfigType.INBOX_AUTOMATIC_TAGS)) {
return null; return null;
} }
TagDao tagDao = new TagDao(); TagDao tagDao = new TagDao();
List<TagDto> tags = tagDao.findByCriteria(new TagCriteria().setTargetIdList(null), new SortCriteria(1, true)); List<TagDto> tags = tagDao.findByCriteria(new TagCriteria().setTargetIdList(null), new SortCriteria(1, true));
HashMap<String, String> tagsNameToId = new HashMap<>(); Map<String, String> tagsNameToId = new HashMap<>();
for (TagDto tagDto : tags) { for (TagDto tagDto : tags) {
tagsNameToId.put(tagDto.getName(), tagDto.getId()); tagsNameToId.put(tagDto.getName(), tagDto.getId());
} }

View File

@ -396,6 +396,8 @@ public class AppResource extends BaseResource {
* @apiName PostAppConfigInbox * @apiName PostAppConfigInbox
* @apiGroup App * @apiGroup App
* @apiParam {Boolean} enabled True if the inbox scanning is enabled * @apiParam {Boolean} enabled True if the inbox scanning is enabled
* @apiParam {Boolean} autoTagsEnabled If true automatically add tags to document (prefixed by #)
* @apiParam {Boolean} deleteImported If true delete message from mailbox after import
* @apiParam {String} hostname IMAP hostname * @apiParam {String} hostname IMAP hostname
* @apiParam {Integer} port IMAP port * @apiParam {Integer} port IMAP port
* @apiParam {String} username IMAP username * @apiParam {String} username IMAP username
@ -432,6 +434,8 @@ public class AppResource extends BaseResource {
} }
checkBaseFunction(BaseFunction.ADMIN); checkBaseFunction(BaseFunction.ADMIN);
ValidationUtil.validateRequired(enabled, "enabled"); ValidationUtil.validateRequired(enabled, "enabled");
ValidationUtil.validateRequired(autoTagsEnabled, "autoTagsEnabled");
ValidationUtil.validateRequired(deleteImported, "deleteImported");
if (!Strings.isNullOrEmpty(portStr)) { if (!Strings.isNullOrEmpty(portStr)) {
ValidationUtil.validateInteger(portStr, "port"); ValidationUtil.validateInteger(portStr, "port");
} }