Commit 17361803 17361803d1890f7b3c738546ee45520191ea4d0f by Sergey Poznyakoff

Output only those list items that match given wildcard expression.

1 parent ee3fc423
...@@ -27,10 +27,11 @@ imap4d_lsub (struct imap4d_command *command, char *arg) ...@@ -27,10 +27,11 @@ imap4d_lsub (struct imap4d_command *command, char *arg)
27 char *sp; 27 char *sp;
28 char *ref; 28 char *ref;
29 char *wcard; 29 char *wcard;
30 char *file; 30 char *file = NULL;
31 char *pattern = NULL;
31 const char *delim = "/"; 32 const char *delim = "/";
32 FILE *fp; 33 FILE *fp;
33 34
34 if (! (command->states & state)) 35 if (! (command->states & state))
35 return util_finish (command, RESP_BAD, "Wrong state"); 36 return util_finish (command, RESP_BAD, "Wrong state");
36 37
...@@ -43,21 +44,34 @@ imap4d_lsub (struct imap4d_command *command, char *arg) ...@@ -43,21 +44,34 @@ imap4d_lsub (struct imap4d_command *command, char *arg)
43 util_unquote (&ref); 44 util_unquote (&ref);
44 util_unquote (&wcard); 45 util_unquote (&wcard);
45 46
46 /* FIXME: Get the matching in list. */ 47 asprintf (&pattern, "%s%s", ref, wcard);
48 if (!pattern)
49 return util_finish (command, RESP_NO, "Not enough memory");
50
47 asprintf (&file, "%s/.mailboxlist", homedir); 51 asprintf (&file, "%s/.mailboxlist", homedir);
52 if (!file)
53 {
54 free (pattern);
55 return util_finish (command, RESP_NO, "Not enough memory");
56 }
57
48 fp = fopen (file, "r"); 58 fp = fopen (file, "r");
49 free (file); 59 free (file);
50 if (fp) 60 if (fp)
51 { 61 {
52 char buffer[124]; 62 char *buf = NULL;
53 while (fgets (buffer, sizeof (buffer), fp)) 63 size_t n = 0;
54 { 64
55 size_t n = strlen (buffer); 65 while (getline(&buf, &n, fp) > 0)
56 if (n && buffer[n - 1] == '\n') 66 {
57 buffer[n - 1] = '\0'; 67 int len = strlen (buf);
58 util_out (RESP_NONE, "LIST () \"%s\" %s", delim, buffer); 68 if (buf[len - 1] == '\n')
59 } 69 buf[len - 1] = '\0';
70 if (util_wcard_match (buf, pattern, delim) != WCARD_NOMATCH)
71 util_out (RESP_NONE, "LIST () \"%s\" %s", delim, buf);
72 }
60 fclose (fp); 73 fclose (fp);
74 free (buf);
61 return util_finish (command, RESP_OK, "Completed"); 75 return util_finish (command, RESP_OK, "Completed");
62 } 76 }
63 else if (errno == ENOENT) 77 else if (errno == ENOENT)
......