Commit 29d84e71 29d84e71986f154374d02ed1975cd667dbd1b4ef by Alain Magloire

* mail/util.c (util_expand_msglist): Implement expansion of

        :d       All deleted messages
        :n       All new messages
        :o       All old messages
        :r       All messages that have already been read
        :u       All unread messages
        /string  All messages with string in the subject line
                 (the case of characters in string is ignored)
1 parent 284950f5
1 2001-06-29 Alain Magloire
2
3 * mail/util.c (util_expand_msglist): Implement expansion of
4 :d All deleted messages
5 :n All new messages
6 :o All old messages
7 :r All messages that have already been read
8 :u All unread messages
9 /string All messages with string in the subject line
10 (the case of characters in string is ignored)
11
1 2001-06-27 Alain Magloire 12 2001-06-27 Alain Magloire
2 13
3 * configure.in: We were not checking for thread support 14 * configure.in: We were not checking for thread support
......
...@@ -152,41 +152,69 @@ util_expand_msglist (const int argc, char **argv, int **list) ...@@ -152,41 +152,69 @@ util_expand_msglist (const int argc, char **argv, int **list)
152 } 152 }
153 else if (argv[i][0] == '/') 153 else if (argv[i][0] == '/')
154 { 154 {
155 /* FIXME: all messages with pattern following / in 155 /* All messages with pattern following / in
156 the subject line, case insensitive */ 156 the subject line, case insensitive */
157 /* This currently appears to be quit b0rked */ 157 int j;
158 message_t msg;
159 header_t hdr;
160 char subj[128];
161 int j = 1, k = 0, l2 = 0;
162 int len = strlen (&argv[i][1]);
163 for (j = 1; j <= total; j++) 158 for (j = 1; j <= total; j++)
164 { 159 {
160 message_t msg = NULL;
161 header_t hdr = NULL;
162 char *subject = NULL;
163 size_t subjlen;
164 char *pattern;
165 size_t patlen;
166 int k;
167
165 mailbox_get_message (mbox, j, &msg); 168 mailbox_get_message (mbox, j, &msg);
166 message_get_header (msg, &hdr); 169 message_get_header (msg, &hdr);
167 header_get_value (hdr, MU_HEADER_SUBJECT, subj, 128, NULL); 170
168 l2 = strlen (subj); 171 header_aget_value (hdr, MU_HEADER_SUBJECT, &subject);
169 for (k = 0; i < strlen (subj); k++) 172 subjlen = (subject) ? strlen (subject) : 0;
173 for (k = 0; k < subjlen; k++)
174 subject[k] = toupper ((int)subject[k]);
175
176 pattern = strdup (&argv[i][1]);
177 patlen = (pattern) ? strlen (pattern) : 0;
178 for (k = 0; k < patlen; k++)
179 pattern[k] = toupper ((int)pattern[k]);
180
181 if (pattern && subject && strstr (subject, pattern))
170 { 182 {
171 if (l2-k >= len && !strncasecmp (&argv[i][1], &subj[k], len)) 183 current = util_ll_add (current, j);
172 {
173 current = util_ll_add (current, j);
174 k = 128;
175 }
176 } 184 }
185
186 free (pattern);
187 free (subject);
177 } 188 }
178 } 189 }
179 else if (argv[i][0] == ':') 190 else if (argv[i][0] == ':')
180 { 191 {
181 /* FIXME: all messages of type argv[i][1] */ 192 /* All messages of type argv[i][1] */
193 int j;
194 for (j = 1; j <= total; j++)
195 {
196 message_t msg = NULL;
197 attribute_t attr= NULL;
198
199 mailbox_get_message (mbox, j, &msg);
200 message_get_attribute (msg, &attr);
201 if ((argv[i][1] == 'd' && attribute_is_deleted (attr))
202 || (argv[i][1] == 'n' && attribute_is_recent (attr))
203 || (argv[i][1] == 'o' && attribute_is_seen (attr))
204 || (argv[i][1] == 'r' && attribute_is_read (attr))
205 || (argv[i][1] == 'u' && !attribute_is_read (attr)))
206 current = util_ll_add (current, j);
207 }
182 } 208 }
183 else if (isalpha(argv[i][0])) 209 else if (isalpha(argv[i][0]))
184 { 210 {
185 /* FIXME: all messages from sender argv[i] */ 211 /* FIXME: all messages from sender argv[i] */
212 /* Annoying we can use address_create() for that
213 but to compare against what? The email ? */
186 } 214 }
187 else if (strchr (argv[i], '-') != NULL) 215 else if (strchr (argv[i], '-') != NULL)
188 { 216 {
189 /* message range */ 217 /* Message range. */
190 int j, x, y; 218 int j, x, y;
191 char *arg = strdup (argv[i]); 219 char *arg = strdup (argv[i]);
192 for (j=0; j < strlen (arg); j++) 220 for (j=0; j < strlen (arg); j++)
...@@ -201,7 +229,7 @@ util_expand_msglist (const int argc, char **argv, int **list) ...@@ -201,7 +229,7 @@ util_expand_msglist (const int argc, char **argv, int **list)
201 } 229 }
202 else 230 else
203 { 231 {
204 /* single message */ 232 /* Single message. */
205 current = util_ll_add (current, strtol (argv[i], NULL, 10)); 233 current = util_ll_add (current, strtol (argv[i], NULL, 10));
206 } 234 }
207 } 235 }
...@@ -252,13 +280,13 @@ util_do_command (const char *c, ...) ...@@ -252,13 +280,13 @@ util_do_command (const char *c, ...)
252 char *cmd = NULL; 280 char *cmd = NULL;
253 va_list ap; 281 va_list ap;
254 int i, zcnt = 0; 282 int i, zcnt = 0;
255 283
256 va_start (ap, c); 284 va_start (ap, c);
257 status = vasprintf (&cmd, c, ap); 285 status = vasprintf (&cmd, c, ap);
258 va_end (ap); 286 va_end (ap);
259 if (status < 0) 287 if (status < 0)
260 return 0; 288 return 0;
261 289
262 if (cmd) 290 if (cmd)
263 { 291 {
264 struct mail_command_entry entry; 292 struct mail_command_entry entry;
...@@ -290,7 +318,7 @@ util_do_command (const char *c, ...) ...@@ -290,7 +318,7 @@ util_do_command (const char *c, ...)
290 zcnt++; 318 zcnt++;
291 } 319 }
292 } 320 }
293 321
294 entry = util_find_entry (argv[0]); 322 entry = util_find_entry (argv[0]);
295 323
296 if (if_cond() == 0 && entry.isflow == 0) 324 if (if_cond() == 0 && entry.isflow == 0)
...@@ -320,7 +348,7 @@ util_do_command (const char *c, ...) ...@@ -320,7 +348,7 @@ util_do_command (const char *c, ...)
320 * func is the function to run 348 * func is the function to run
321 * argc is the number of arguments inculding the command and msglist 349 * argc is the number of arguments inculding the command and msglist
322 * argv is the list of strings containing the command and msglist 350 * argv is the list of strings containing the command and msglist
323 * set_cursor means whether the function should set the cursor to 351 * set_cursor means whether the function should set the cursor to
324 * the number of the last message processed. If set_cursor = 0, the 352 * the number of the last message processed. If set_cursor = 0, the
325 * cursor is not altered. 353 * cursor is not altered.
326 */ 354 */
...@@ -424,7 +452,7 @@ util_screen_lines() ...@@ -424,7 +452,7 @@ util_screen_lines()
424 { 452 {
425 struct mail_env_entry *ep = util_find_env("screen"); 453 struct mail_env_entry *ep = util_find_env("screen");
426 size_t n; 454 size_t n;
427 455
428 if (ep && ep->set && (n = atoi(ep->value)) != 0) 456 if (ep && ep->set && (n = atoi(ep->value)) != 0)
429 return n; 457 return n;
430 return util_getlines(); 458 return util_getlines();
...@@ -625,7 +653,7 @@ util_get_homedir() ...@@ -625,7 +653,7 @@ util_get_homedir()
625 } 653 }
626 return strdup(homedir); 654 return strdup(homedir);
627 } 655 }
628 656
629 char * 657 char *
630 util_fullpath(char *inpath) 658 util_fullpath(char *inpath)
631 { 659 {
...@@ -639,7 +667,7 @@ util_get_sender(int msgno, int strip) ...@@ -639,7 +667,7 @@ util_get_sender(int msgno, int strip)
639 address_t addr = NULL; 667 address_t addr = NULL;
640 message_t msg = NULL; 668 message_t msg = NULL;
641 char buffer[512], *p; 669 char buffer[512], *p;
642 670
643 mailbox_get_message (mbox, msgno, &msg); 671 mailbox_get_message (mbox, msgno, &msg);
644 message_get_header (msg, &header); 672 message_get_header (msg, &header);
645 if (header_get_value (header, MU_HEADER_FROM, buffer, sizeof(buffer), NULL) 673 if (header_get_value (header, MU_HEADER_FROM, buffer, sizeof(buffer), NULL)
...@@ -661,14 +689,14 @@ util_get_sender(int msgno, int strip) ...@@ -661,14 +689,14 @@ util_get_sender(int msgno, int strip)
661 address_destroy (&addr); 689 address_destroy (&addr);
662 return NULL; 690 return NULL;
663 } 691 }
664 692
665 if (strip) 693 if (strip)
666 { 694 {
667 p = strchr (buffer, '@'); 695 p = strchr (buffer, '@');
668 if (p) 696 if (p)
669 *p = 0; 697 *p = 0;
670 } 698 }
671 699
672 p = strdup (buffer); 700 p = strdup (buffer);
673 address_destroy (&addr); 701 address_destroy (&addr);
674 return p; 702 return p;
...@@ -679,15 +707,15 @@ util_slist_print(list_t list, int nl) ...@@ -679,15 +707,15 @@ util_slist_print(list_t list, int nl)
679 { 707 {
680 iterator_t itr; 708 iterator_t itr;
681 char *name; 709 char *name;
682 710
683 if (!list || iterator_create (&itr, list)) 711 if (!list || iterator_create (&itr, list))
684 return; 712 return;
685 713
686 for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr)) 714 for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr))
687 { 715 {
688 iterator_current (itr, (void **)&name); 716 iterator_current (itr, (void **)&name);
689 fprintf (ofile, "%s%c", name, nl ? '\n' : ' '); 717 fprintf (ofile, "%s%c", name, nl ? '\n' : ' ');
690 718
691 } 719 }
692 iterator_destroy (&itr); 720 iterator_destroy (&itr);
693 } 721 }
...@@ -698,10 +726,10 @@ util_slist_lookup(list_t list, char *str) ...@@ -698,10 +726,10 @@ util_slist_lookup(list_t list, char *str)
698 iterator_t itr; 726 iterator_t itr;
699 char *name; 727 char *name;
700 int rc = 0; 728 int rc = 0;
701 729
702 if (!list || iterator_create (&itr, list)) 730 if (!list || iterator_create (&itr, list))
703 return 0; 731 return 0;
704 732
705 for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr)) 733 for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr))
706 { 734 {
707 iterator_current (itr, (void **)&name); 735 iterator_current (itr, (void **)&name);
...@@ -719,10 +747,10 @@ void ...@@ -719,10 +747,10 @@ void
719 util_slist_add (list_t *list, char *value) 747 util_slist_add (list_t *list, char *value)
720 { 748 {
721 char *p; 749 char *p;
722 750
723 if (!*list && list_create (list)) 751 if (!*list && list_create (list))
724 return; 752 return;
725 753
726 if ((p = strdup(value)) == NULL) 754 if ((p = strdup(value)) == NULL)
727 { 755 {
728 fprintf (ofile, "not enough memory\n"); 756 fprintf (ofile, "not enough memory\n");
...@@ -736,10 +764,10 @@ util_slist_destroy (list_t *list) ...@@ -736,10 +764,10 @@ util_slist_destroy (list_t *list)
736 { 764 {
737 iterator_t itr; 765 iterator_t itr;
738 char *name; 766 char *name;
739 767
740 if (!*list || iterator_create (&itr, *list)) 768 if (!*list || iterator_create (&itr, *list))
741 return; 769 return;
742 770
743 for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr)) 771 for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr))
744 { 772 {
745 iterator_current (itr, (void **)&name); 773 iterator_current (itr, (void **)&name);
...@@ -755,10 +783,10 @@ util_slist_to_string (list_t list, char *delim) ...@@ -755,10 +783,10 @@ util_slist_to_string (list_t list, char *delim)
755 iterator_t itr; 783 iterator_t itr;
756 char *name; 784 char *name;
757 char *str = NULL; 785 char *str = NULL;
758 786
759 if (!list || iterator_create (&itr, list)) 787 if (!list || iterator_create (&itr, list))
760 return NULL; 788 return NULL;
761 789
762 for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr)) 790 for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr))
763 { 791 {
764 iterator_current (itr, (void **)&name); 792 iterator_current (itr, (void **)&name);
...@@ -788,14 +816,14 @@ util_strcat(char **dest, char *str) ...@@ -788,14 +816,14 @@ util_strcat(char **dest, char *str)
788 memcpy (newp + dlen - 1, str, slen); 816 memcpy (newp + dlen - 1, str, slen);
789 } 817 }
790 } 818 }
791 819
792 void 820 void
793 util_escape_percent (char **str) 821 util_escape_percent (char **str)
794 { 822 {
795 int count; 823 int count;
796 char *p, *q; 824 char *p, *q;
797 char *newstr; 825 char *newstr;
798 826
799 /* Count ocurrences of % in the string */ 827 /* Count ocurrences of % in the string */
800 count = 0; 828 count = 0;
801 for (p = *str; *p; p++) 829 for (p = *str; *p; p++)
...@@ -805,7 +833,7 @@ util_escape_percent (char **str) ...@@ -805,7 +833,7 @@ util_escape_percent (char **str)
805 if (!count) 833 if (!count)
806 return; /* nothing to do */ 834 return; /* nothing to do */
807 835
808 /* expand the string */ 836 /* expand the string */
809 newstr = malloc (strlen (*str) + 1 + count); 837 newstr = malloc (strlen (*str) + 1 + count);
810 if (!newstr) 838 if (!newstr)
811 { 839 {
...@@ -813,7 +841,7 @@ util_escape_percent (char **str) ...@@ -813,7 +841,7 @@ util_escape_percent (char **str)
813 exit (1); /* be on the safe side */ 841 exit (1); /* be on the safe side */
814 } 842 }
815 843
816 /* and escape percent signs */ 844 /* and escape percent signs */
817 p = newstr; 845 p = newstr;
818 q = *str; 846 q = *str;
819 while (*p = *q++) 847 while (*p = *q++)
...@@ -837,7 +865,7 @@ util_outfolder_name (char *str) ...@@ -837,7 +865,7 @@ util_outfolder_name (char *str)
837 case '+': 865 case '+':
838 str = util_fullpath (str); 866 str = util_fullpath (str);
839 break; 867 break;
840 868
841 default: 869 default:
842 if (ep && ep->set) 870 if (ep && ep->set)
843 { 871 {
...@@ -881,14 +909,14 @@ util_save_outgoing (message_t msg, char *savefile) ...@@ -881,14 +909,14 @@ util_save_outgoing (message_t msg, char *savefile)
881 { 909 {
882 char *buf; 910 char *buf;
883 size_t bsize = 0; 911 size_t bsize = 0;
884 912
885 message_size (msg, &bsize); 913 message_size (msg, &bsize);
886 914
887 /* Try to allocate large buffer */ 915 /* Try to allocate large buffer */
888 for (; bsize > 1; bsize /= 2) 916 for (; bsize > 1; bsize /= 2)
889 if ((buf = malloc (bsize))) 917 if ((buf = malloc (bsize)))
890 break; 918 break;
891 919
892 if (!bsize) 920 if (!bsize)
893 { 921 {
894 fprintf (ofile, "not enough memory for creating save file\n"); 922 fprintf (ofile, "not enough memory for creating save file\n");
...@@ -920,8 +948,3 @@ util_save_outgoing (message_t msg, char *savefile) ...@@ -920,8 +948,3 @@ util_save_outgoing (message_t msg, char *savefile)
920 free (filename); 948 free (filename);
921 } 949 }
922 } 950 }
923
924
925
926
927
......
...@@ -85,7 +85,7 @@ main(int argc, char **argv) ...@@ -85,7 +85,7 @@ main(int argc, char **argv)
85 msgset (argc - 1, &argv[1], &set, &n); 85 msgset (argc - 1, &argv[1], &set, &n);
86 else 86 else
87 { 87 {
88 char *av[] = { "*" }; 88 const char *av[] = { "*" };
89 msgset (1, av, &set, &n); 89 msgset (1, av, &set, &n);
90 } 90 }
91 91
......