For consistency, reduced all operations
with flags to manipulations with _imap4d_attrlist array RFC2060 states that \Seen flag means "Message has been read", so it should be mapped to our MU_ATTRIBUTE_READ. (util_print_flags, util_attribute_matches_flag): New functions.
Showing
1 changed file
with
66 additions
and
25 deletions
... | @@ -731,6 +731,7 @@ util_strcasestr (const char *haystack, const char *needle) | ... | @@ -731,6 +731,7 @@ util_strcasestr (const char *haystack, const char *needle) |
731 | return NULL; | 731 | return NULL; |
732 | } | 732 | } |
733 | 733 | ||
734 | |||
734 | struct | 735 | struct |
735 | { | 736 | { |
736 | char *name; | 737 | char *name; |
... | @@ -740,7 +741,7 @@ struct | ... | @@ -740,7 +741,7 @@ struct |
740 | { "\\Flagged", MU_ATTRIBUTE_FLAGGED }, | 741 | { "\\Flagged", MU_ATTRIBUTE_FLAGGED }, |
741 | { "\\Deleted", MU_ATTRIBUTE_DELETED }, | 742 | { "\\Deleted", MU_ATTRIBUTE_DELETED }, |
742 | { "\\Draft", MU_ATTRIBUTE_DRAFT }, | 743 | { "\\Draft", MU_ATTRIBUTE_DRAFT }, |
743 | { "\\Seen", MU_ATTRIBUTE_SEEN }, | 744 | { "\\Seen", MU_ATTRIBUTE_READ }, |
744 | { "\\Recent", MU_ATTRIBUTE_RECENT }, | 745 | { "\\Recent", MU_ATTRIBUTE_RECENT }, |
745 | }; | 746 | }; |
746 | 747 | ||
... | @@ -761,44 +762,84 @@ util_attribute_to_type (const char *item, int *type) | ... | @@ -761,44 +762,84 @@ util_attribute_to_type (const char *item, int *type) |
761 | return 1; | 762 | return 1; |
762 | } | 763 | } |
763 | 764 | ||
765 | /* Note: currently unused. Not needed, possibly? */ | ||
764 | int | 766 | int |
765 | util_type_to_attribute (int type, char **attr_str) | 767 | util_type_to_attribute (int type, char **attr_str) |
766 | { | 768 | { |
767 | *attr_str = NULL; | 769 | char *attr_list[NATTR]; |
768 | if (type == MU_ATTRIBUTE_RECENT) | 770 | int nattr = 0; |
771 | int i; | ||
772 | size_t len = 0; | ||
773 | |||
774 | if (MU_ATTRIBUTE_IS_UNSEEN(type)) | ||
769 | *attr_str = strdup("\\Recent"); | 775 | *attr_str = strdup("\\Recent"); |
770 | else | 776 | else |
771 | { | 777 | *attr_str = NULL; |
772 | char *attr_list[NATTR]; | ||
773 | int nattr = 0; | ||
774 | int i; | ||
775 | size_t len = 0; | ||
776 | 778 | ||
777 | for (i = 0; i < _imap4d_nattr; i++) | 779 | for (i = 0; i < _imap4d_nattr; i++) |
778 | if (type & _imap4d_attrlist[i].flag) | 780 | if (type & _imap4d_attrlist[i].flag) |
779 | { | 781 | { |
780 | attr_list[nattr++] = _imap4d_attrlist[i].name; | 782 | attr_list[nattr++] = _imap4d_attrlist[i].name; |
781 | len += 1 + strlen(_imap4d_attrlist[i].name); | 783 | len += 1 + strlen(_imap4d_attrlist[i].name); |
782 | } | 784 | } |
783 | 785 | ||
784 | *attr_str = malloc(len+1); | 786 | *attr_str = malloc(len+1); |
785 | (*attr_str)[0] = 0; | 787 | (*attr_str)[0] = 0; |
786 | if (*attr_str) | 788 | if (*attr_str) |
789 | { | ||
790 | for (i = 0; i < nattr; i++) | ||
787 | { | 791 | { |
788 | for (i = 0; i < nattr; i++) | 792 | strcat(*attr_str, attr_list[i]); |
789 | { | 793 | if (i != nattr-1) |
790 | strcat(*attr_str, attr_list[i]); | 794 | strcat(*attr_str, " "); |
791 | if (i != nattr-1) | ||
792 | strcat(*attr_str, " "); | ||
793 | } | ||
794 | } | 795 | } |
795 | } | 796 | } |
796 | 797 | ||
797 | if (!*attr_str) | 798 | if (!*attr_str) |
798 | imap4d_bye (ERR_NO_MEM); | 799 | imap4d_bye (ERR_NO_MEM); |
799 | return 0; | 800 | return 0; |
800 | } | 801 | } |
801 | 802 | ||
803 | void | ||
804 | util_print_flags(attribute_t attr) | ||
805 | { | ||
806 | int i; | ||
807 | int flags = 0; | ||
808 | int space = 0; | ||
809 | |||
810 | attribute_get_flags (attr, &flags); | ||
811 | for (i = 0; i < _imap4d_nattr; i++) | ||
812 | if (flags & _imap4d_attrlist[i].flag) | ||
813 | { | ||
814 | if (space) | ||
815 | util_send (" "); | ||
816 | else | ||
817 | space = 1; | ||
818 | util_send (_imap4d_attrlist[i].name); | ||
819 | } | ||
820 | |||
821 | if (MU_ATTRIBUTE_IS_UNSEEN(flags)) | ||
822 | { | ||
823 | if (space) | ||
824 | util_send (" "); | ||
825 | util_send ("\\Recent"); | ||
826 | } | ||
827 | } | ||
828 | |||
829 | int | ||
830 | util_attribute_matches_flag (attribute_t attr, const char *item) | ||
831 | { | ||
832 | int flags = 0, mask = 0; | ||
833 | |||
834 | attribute_get_flags (attr, &flags); | ||
835 | util_attribute_to_type (item, &mask); | ||
836 | if (mask == MU_ATTRIBUTE_RECENT) | ||
837 | return MU_ATTRIBUTE_IS_UNSEEN (flags); | ||
838 | |||
839 | return flags & mask; | ||
840 | } | ||
841 | |||
842 | |||
802 | int | 843 | int |
803 | util_parse_attributes(char *items, char **save, int *flags) | 844 | util_parse_attributes(char *items, char **save, int *flags) |
804 | { | 845 | { | ... | ... |
-
Please register or sign in to post a comment