diff --git a/dev/View/Popup/AdvancedSearch.js b/dev/View/Popup/AdvancedSearch.js index 220d12477..00c86058b 100644 --- a/dev/View/Popup/AdvancedSearch.js +++ b/dev/View/Popup/AdvancedSearch.js @@ -1,6 +1,7 @@ import { koComputable } from 'External/ko'; import { i18n, trigger as translatorTrigger } from 'Common/Translator'; +import { pString } from 'Common/Utils'; import { MessagelistUserStore } from 'Stores/User/Messagelist'; @@ -70,55 +71,38 @@ export class AdvancedSearchPopupView extends AbstractViewPopup { this.close(); } - parseSearchStringValue(search) { - const parts = (search || '').split(/[\s]+/g); - parts.forEach(part => { - switch (part) { - case 'has:attachment': - this.hasAttachment(true); - break; - case 'is:unseen,flagged': - this.starred(true); - /* falls through */ - case 'is:unseen': - this.unseen(true); - break; - // no default - } - }); - } - buildSearchString() { const + self = this, data = new FormData(), append = (key, value) => value.length && data.append(key, value); - append('from', this.from().trim()); - append('to', this.to().trim()); - append('subject', this.subject().trim()); - append('text', this.text().trim()); - append('in', this.selectedTreeValue()); - if (-1 < this.selectedDateValue()) { + append('from', self.from().trim()); + append('to', self.to().trim()); + append('subject', self.subject().trim()); + append('text', self.text().trim()); + append('in', self.selectedTreeValue()); + if (-1 < self.selectedDateValue()) { let d = new Date(); - d.setDate(d.getDate() - this.selectedDateValue()); + d.setDate(d.getDate() - self.selectedDateValue()); append('since', d.toISOString().split('T')[0]); } let result = new URLSearchParams(data).toString(); - if (this.hasAttachment()) { + if (self.hasAttachment()) { result += '&attachment'; } - if (this.unseen()) { + if (self.unseen()) { result += '&unseen'; } - if (this.starred()) { + if (self.starred()) { result += '&flagged'; } - if (1 == this.repliedValue()) { + if (1 == self.repliedValue()) { result += '&answered'; } - if (0 == this.repliedValue()) { + if (0 == self.repliedValue()) { result += '&unanswered'; } @@ -126,17 +110,22 @@ export class AdvancedSearchPopupView extends AbstractViewPopup { } onShow(search) { - this.from(''); - this.to(''); - this.subject(''); - this.text(''); - - this.repliedValue(-1); - this.selectedDateValue(-1); - this.hasAttachment(false); - this.starred(false); - this.unseen(false); - - this.parseSearchStringValue(search); + const self = this, + params = new URLSearchParams('?'+search); + self.from(pString(params.get('from'))); + self.to(pString(params.get('to'))); + self.subject(pString(params.get('subject'))); + self.text(pString(params.get('text'))); + self.selectedTreeValue(pString(params.get('in'))); +// self.selectedDateValue(params.get('since')); + self.selectedDateValue(-1); + self.hasAttachment(params.has('attachment')); + self.starred(params.has('flagged')); + self.unseen(params.has('unseen')); + if (params.has('answered')) { + self.repliedValue(1); + } else if (params.has('unanswered')) { + self.repliedValue(0); + } } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/SearchCriterias.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/SearchCriterias.php index 17e02a409..2976d511a 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/SearchCriterias.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/SearchCriterias.php @@ -387,7 +387,7 @@ abstract class SearchCriterias $aCache = array(); $sSearch = \MailSo\Base\Utils::StripSpaces($sSearch); - $sSearch = \trim(\preg_replace('/('.static::RegEx.'): /i', '\\1:', $sSearch)); + $sSearch = \trim(\preg_replace('/('.static::RegEx.'):\\s+/i', '\\1:', $sSearch)); $mMatch = array(); if (\preg_match_all('/".*?(?