234 { |
234 { |
235 if (filter._comparatorType == QMessageFilterPrivate::Equality) { |
235 if (filter._comparatorType == QMessageFilterPrivate::Equality) { |
236 QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue)); |
236 QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue)); |
237 if (cmp == QMessageDataComparator::Equal) { |
237 if (cmp == QMessageDataComparator::Equal) { |
238 if (filter._value.toString().length() > 0) { |
238 if (filter._value.toString().length() > 0) { |
239 if (message.from().recipient().compare(filter._value.toString(),caseSensitivity) == 0) { |
239 if (message.from().addressee().compare(filter._value.toString(),caseSensitivity) == 0) { |
240 return true; |
240 return true; |
241 } |
241 } |
242 } |
242 } |
243 } else { // NotEqual |
243 } else { // NotEqual |
244 if (filter._value.toString().length() > 0) { |
244 if (filter._value.toString().length() > 0) { |
245 if (message.from().recipient().compare(filter._value.toString(),caseSensitivity) != 0) { |
245 if (message.from().addressee().compare(filter._value.toString(),caseSensitivity) != 0) { |
246 return true; |
246 return true; |
247 } |
247 } |
248 } else { |
248 } else { |
249 return true; |
249 return true; |
250 } |
250 } |
251 } |
251 } |
252 } else if (filter._comparatorType == QMessageFilterPrivate::Inclusion) { |
252 } else if (filter._comparatorType == QMessageFilterPrivate::Inclusion) { |
253 QMessageDataComparator::InclusionComparator cmp(static_cast<QMessageDataComparator::InclusionComparator>(filter._comparatorValue)); |
253 QMessageDataComparator::InclusionComparator cmp(static_cast<QMessageDataComparator::InclusionComparator>(filter._comparatorValue)); |
254 if (cmp == QMessageDataComparator::Includes) { |
254 if (cmp == QMessageDataComparator::Includes) { |
255 if (message.from().recipient().contains(filter._value.toString(),caseSensitivity)) { |
255 if (message.from().addressee().contains(filter._value.toString(),caseSensitivity)) { |
256 return true; |
256 return true; |
257 } |
257 } |
258 } else { // Excludes |
258 } else { // Excludes |
259 if (!message.from().recipient().contains(filter._value.toString(),caseSensitivity)) { |
259 if (!message.from().addressee().contains(filter._value.toString(),caseSensitivity)) { |
260 return true; |
260 return true; |
261 } |
261 } |
262 } |
262 } |
263 } |
263 } |
264 break; |
264 break; |
269 QMessageDataComparator::InclusionComparator cmp(static_cast<QMessageDataComparator::InclusionComparator>(filter._comparatorValue)); |
269 QMessageDataComparator::InclusionComparator cmp(static_cast<QMessageDataComparator::InclusionComparator>(filter._comparatorValue)); |
270 bool includes = false; |
270 bool includes = false; |
271 // Check to addresses |
271 // Check to addresses |
272 QMessageAddressList addrList = message.to(); |
272 QMessageAddressList addrList = message.to(); |
273 for (int i=0; i < addrList.count(); i++) { |
273 for (int i=0; i < addrList.count(); i++) { |
274 if (addrList[i].recipient().contains(filter._value.toString(),caseSensitivity)) { |
274 if (addrList[i].addressee().contains(filter._value.toString(),caseSensitivity)) { |
275 includes = true; |
275 includes = true; |
276 break; |
276 break; |
277 } |
277 } |
278 } |
278 } |
279 if (!includes) { |
279 if (!includes) { |
280 // Check cc addresses |
280 // Check cc addresses |
281 addrList = message.cc(); |
281 addrList = message.cc(); |
282 for (int i=0; i < addrList.count(); i++) { |
282 for (int i=0; i < addrList.count(); i++) { |
283 if (addrList[i].recipient().contains(filter._value.toString(),caseSensitivity)) { |
283 if (addrList[i].addressee().contains(filter._value.toString(),caseSensitivity)) { |
284 includes = true; |
284 includes = true; |
285 break; |
285 break; |
286 } |
286 } |
287 } |
287 } |
288 } |
288 } |
289 if (!includes) { |
289 if (!includes) { |
290 // Check bcc addresses |
290 // Check bcc addresses |
291 addrList = message.bcc(); |
291 addrList = message.bcc(); |
292 for (int i=0; i < addrList.count(); i++) { |
292 for (int i=0; i < addrList.count(); i++) { |
293 if (addrList[i].recipient().contains(filter._value.toString(),caseSensitivity)) { |
293 if (addrList[i].addressee().contains(filter._value.toString(),caseSensitivity)) { |
294 includes = true; |
294 includes = true; |
295 break; |
295 break; |
296 } |
296 } |
297 } |
297 } |
298 } |
298 } |
495 case QMessageFilterPrivate::Size: |
495 case QMessageFilterPrivate::Size: |
496 { |
496 { |
497 if (filter._comparatorType == QMessageFilterPrivate::Equality) { |
497 if (filter._comparatorType == QMessageFilterPrivate::Equality) { |
498 QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue)); |
498 QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue)); |
499 if (cmp == QMessageDataComparator::Equal) { |
499 if (cmp == QMessageDataComparator::Equal) { |
500 if (message.size() == filter._value.toUInt()) { |
500 if (message.size() == filter._value.toInt()) { |
501 return true; |
501 return true; |
502 } |
502 } |
503 } else { // NotEqual |
503 } else { // NotEqual |
504 if (message.size() != filter._value.toUInt()) { |
504 if (message.size() != filter._value.toInt()) { |
505 return true; |
505 return true; |
506 } |
506 } |
507 } |
507 } |
508 } else if (filter._comparatorType == QMessageFilterPrivate::Relation) { |
508 } else if (filter._comparatorType == QMessageFilterPrivate::Relation) { |
509 QMessageDataComparator::RelationComparator cmp(static_cast<QMessageDataComparator::RelationComparator>(filter._comparatorValue)); |
509 QMessageDataComparator::RelationComparator cmp(static_cast<QMessageDataComparator::RelationComparator>(filter._comparatorValue)); |
510 if (cmp == QMessageDataComparator::LessThan) { |
510 if (cmp == QMessageDataComparator::LessThan) { |
511 if (message.size() < filter._value.toUInt()) { |
511 if (message.size() < filter._value.toInt()) { |
512 return true; |
512 return true; |
513 } |
513 } |
514 } else if (cmp == QMessageDataComparator::LessThanEqual) { |
514 } else if (cmp == QMessageDataComparator::LessThanEqual) { |
515 if (message.size() <= filter._value.toUInt()) { |
515 if (message.size() <= filter._value.toInt()) { |
516 return true; |
516 return true; |
517 } |
517 } |
518 } else if (cmp == QMessageDataComparator::GreaterThan) { |
518 } else if (cmp == QMessageDataComparator::GreaterThan) { |
519 if (message.size() > filter._value.toUInt()) { |
519 if (message.size() > filter._value.toInt()) { |
520 return true; |
520 return true; |
521 } |
521 } |
522 } else { // GreaterThanEqual |
522 } else { // GreaterThanEqual |
523 if (message.size() >= filter._value.toUInt()) { |
523 if (message.size() >= filter._value.toInt()) { |
524 return true; |
524 return true; |
525 } |
525 } |
526 } |
526 } |
527 } |
527 } |
528 break; |
528 break; |
649 } |
649 } |
650 |
650 |
651 QMessageFilter::QMessageFilter() |
651 QMessageFilter::QMessageFilter() |
652 : d_ptr(new QMessageFilterPrivate(this)) |
652 : d_ptr(new QMessageFilterPrivate(this)) |
653 { |
653 { |
654 d_ptr->_matchFlags = 0; |
654 d_ptr->_matchFlags = 0; |
655 |
655 |
656 d_ptr->_valid = true; // Empty filter is valid |
656 d_ptr->_valid = true; // Empty filter is valid |
657 d_ptr->_notFilter = false; |
657 d_ptr->_notFilter = false; |
658 d_ptr->_notFilterForComparator = false; |
658 d_ptr->_notFilterForComparator = false; |
659 d_ptr->_ids = QMessageIdList(); |
659 d_ptr->_ids = QMessageIdList(); |
660 d_ptr->_value = QVariant(); |
660 d_ptr->_value = QVariant(); |
661 d_ptr->_field = QMessageFilterPrivate::None; |
661 d_ptr->_field = QMessageFilterPrivate::None; |
662 d_ptr->_comparatorType = QMessageFilterPrivate::Equality; |
662 d_ptr->_comparatorType = QMessageFilterPrivate::Equality; |
663 d_ptr->_comparatorValue = 0; |
663 d_ptr->_comparatorValue = 0; |
664 d_ptr->_accountFilter = 0; |
664 d_ptr->_accountFilter = 0; |
665 d_ptr->_folderFilter = 0; |
665 d_ptr->_folderFilter = 0; |
666 } |
666 } |
667 |
667 |
668 QMessageFilter::QMessageFilter(const QMessageFilter &other) |
668 QMessageFilter::QMessageFilter(const QMessageFilter &other) |
726 } |
726 } |
727 |
727 |
728 bool QMessageFilter::isEmpty() const |
728 bool QMessageFilter::isEmpty() const |
729 { |
729 { |
730 return ((d_ptr->_field == QMessageFilterPrivate::None) && |
730 return ((d_ptr->_field == QMessageFilterPrivate::None) && |
731 (d_ptr->_notFilter == false) && |
731 (d_ptr->_notFilter == false) && |
732 (d_ptr->_filterList.count()) == 0); |
732 (d_ptr->_filterList.count()) == 0); |
733 } |
733 } |
734 |
734 |
735 bool QMessageFilter::isSupported() const |
735 bool QMessageFilter::isSupported() const |
736 { |
736 { |
739 |
739 |
740 QMessageFilter QMessageFilter::operator~() const |
740 QMessageFilter QMessageFilter::operator~() const |
741 { |
741 { |
742 QMessageFilter result(*this); |
742 QMessageFilter result(*this); |
743 if (result.isEmpty()) { |
743 if (result.isEmpty()) { |
744 result.d_ptr->_notFilter = true; |
744 result.d_ptr->_notFilter = true; |
745 } else { |
745 } else { |
746 if (result.d_ptr->_notFilter) { |
746 if (result.d_ptr->_notFilter) { |
747 result.d_ptr->_notFilter = false; |
747 result.d_ptr->_notFilter = false; |
748 } else { |
748 } else { |
749 QMessageFilterPrivate::applyNot(result); |
749 QMessageFilterPrivate::applyNot(result); |
750 } |
750 } |
751 } |
751 } |
752 return result; |
752 return result; |
753 } |
753 } |
754 |
754 |
755 QMessageFilter QMessageFilter::operator&(const QMessageFilter& other) const |
755 QMessageFilter QMessageFilter::operator&(const QMessageFilter& other) const |
766 return result; |
766 return result; |
767 } |
767 } |
768 |
768 |
769 const QMessageFilter& QMessageFilter::operator&=(const QMessageFilter& other) |
769 const QMessageFilter& QMessageFilter::operator&=(const QMessageFilter& other) |
770 { |
770 { |
771 if (&other == this) { |
771 if (&other == this) { |
772 return *this; |
772 return *this; |
773 } |
773 } |
774 |
774 |
775 if (isEmpty()) { |
775 if (isEmpty()) { |
776 *this = other; |
776 *this = other; |
777 return *this; |
777 return *this; |
778 } |
778 } |
779 |
779 |
780 if (other.isEmpty()) { |
780 if (other.isEmpty()) { |
781 return *this; |
781 return *this; |
782 } |
782 } |
783 |
783 |
784 if (d_ptr->_notFilter && !d_ptr->_notFilterForComparator) { |
784 if (d_ptr->_notFilter && !d_ptr->_notFilterForComparator) { |
785 return *this; |
785 return *this; |
786 } |
786 } |
787 |
787 |
788 if (other.d_ptr->_notFilter && !d_ptr->_notFilterForComparator) { |
788 if (other.d_ptr->_notFilter && !d_ptr->_notFilterForComparator) { |
789 *this = other; |
789 *this = other; |
790 return *this; |
790 return *this; |
791 } |
791 } |
792 |
792 |
793 if (d_ptr->_filterList.count() == 0) { |
793 if (d_ptr->_filterList.count() == 0) { |
794 QMessageFilter newFilter = QMessageFilter(*this); |
794 QMessageFilter newFilter = QMessageFilter(*this); |
795 d_ptr->_filterList.append(QMessageFilterPrivate::SortedMessageFilterList()); |
795 d_ptr->_filterList.append(QMessageFilterPrivate::SortedMessageFilterList()); |
796 d_ptr->_filterList[0] << newFilter; |
796 d_ptr->_filterList[0] << newFilter; |
827 return *this; |
827 return *this; |
828 } |
828 } |
829 |
829 |
830 const QMessageFilter& QMessageFilter::operator|=(const QMessageFilter& other) |
830 const QMessageFilter& QMessageFilter::operator|=(const QMessageFilter& other) |
831 { |
831 { |
832 if (&other == this) { |
832 if (&other == this) { |
833 return *this; |
833 return *this; |
834 } |
834 } |
835 |
835 |
836 if (isEmpty()) { |
836 if (isEmpty()) { |
837 return *this; |
837 return *this; |
838 } |
838 } |
839 |
839 |
840 if (other.isEmpty()) { |
840 if (other.isEmpty()) { |
841 *this = other; |
841 *this = other; |
842 return *this; |
842 return *this; |
843 } |
843 } |
844 |
844 |
845 if (d_ptr->_notFilter && !d_ptr->_notFilterForComparator) { |
845 if (d_ptr->_notFilter && !d_ptr->_notFilterForComparator) { |
846 *this = other; |
846 *this = other; |
847 return *this; |
847 return *this; |
848 } |
848 } |
849 |
849 |
850 if (other.d_ptr->_notFilter && !d_ptr->_notFilterForComparator) { |
850 if (other.d_ptr->_notFilter && !d_ptr->_notFilterForComparator) { |
851 return *this; |
851 return *this; |
852 } |
852 } |
853 |
853 |
854 if (d_ptr->_filterList.count() == 0) { |
854 if (d_ptr->_filterList.count() == 0) { |
855 QMessageFilter newFilter = QMessageFilter(*this); |
855 QMessageFilter newFilter = QMessageFilter(*this); |
856 d_ptr->_filterList.append(QMessageFilterPrivate::SortedMessageFilterList()); |
856 d_ptr->_filterList.append(QMessageFilterPrivate::SortedMessageFilterList()); |
857 d_ptr->_filterList[d_ptr->_filterList.count()-1] << newFilter; |
857 d_ptr->_filterList[d_ptr->_filterList.count()-1] << newFilter; |
1046 } |
1046 } |
1047 |
1047 |
1048 QMessageFilter QMessageFilter::byReceptionTimeStamp(const QDateTime &value, QMessageDataComparator::EqualityComparator cmp) |
1048 QMessageFilter QMessageFilter::byReceptionTimeStamp(const QDateTime &value, QMessageDataComparator::EqualityComparator cmp) |
1049 { |
1049 { |
1050 QMessageFilter result; |
1050 QMessageFilter result; |
1051 result.d_ptr->_field = QMessageFilterPrivate::TimeStamp; |
1051 result.d_ptr->_field = QMessageFilterPrivate::ReceptionTimeStamp; |
1052 result.d_ptr->_value = value; |
1052 result.d_ptr->_value = value; |
1053 result.d_ptr->_comparatorType = QMessageFilterPrivate::Equality; |
1053 result.d_ptr->_comparatorType = QMessageFilterPrivate::Equality; |
1054 result.d_ptr->_comparatorValue = static_cast<int>(cmp); |
1054 result.d_ptr->_comparatorValue = static_cast<int>(cmp); |
1055 result.d_ptr->_valid = true; |
1055 result.d_ptr->_valid = true; |
1056 return result; |
1056 return result; |
1057 } |
1057 } |
1058 |
1058 |
1059 QMessageFilter QMessageFilter::byReceptionTimeStamp(const QDateTime &value, QMessageDataComparator::RelationComparator cmp) |
1059 QMessageFilter QMessageFilter::byReceptionTimeStamp(const QDateTime &value, QMessageDataComparator::RelationComparator cmp) |
1060 { |
1060 { |
1061 QMessageFilter result; |
1061 QMessageFilter result; |
1062 result.d_ptr->_field = QMessageFilterPrivate::TimeStamp; |
1062 result.d_ptr->_field = QMessageFilterPrivate::ReceptionTimeStamp; |
1063 result.d_ptr->_value = value; |
1063 result.d_ptr->_value = value; |
1064 result.d_ptr->_comparatorType = QMessageFilterPrivate::Relation; |
1064 result.d_ptr->_comparatorType = QMessageFilterPrivate::Relation; |
1065 result.d_ptr->_comparatorValue = static_cast<int>(cmp); |
1065 result.d_ptr->_comparatorValue = static_cast<int>(cmp); |
1066 result.d_ptr->_valid = true; |
1066 result.d_ptr->_valid = true; |
1067 return result; |
1067 return result; |