Output only those list items that match given wildcard expression.
Showing
1 changed file
with
22 additions
and
8 deletions
... | @@ -27,7 +27,8 @@ imap4d_lsub (struct imap4d_command *command, char *arg) | ... | @@ -27,7 +27,8 @@ 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 | ||
... | @@ -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; |
64 | |||
65 | while (getline(&buf, &n, fp) > 0) | ||
54 | { | 66 | { |
55 | size_t n = strlen (buffer); | 67 | int len = strlen (buf); |
56 | if (n && buffer[n - 1] == '\n') | 68 | if (buf[len - 1] == '\n') |
57 | buffer[n - 1] = '\0'; | 69 | buf[len - 1] = '\0'; |
58 | util_out (RESP_NONE, "LIST () \"%s\" %s", delim, buffer); | 70 | if (util_wcard_match (buf, pattern, delim) != WCARD_NOMATCH) |
71 | util_out (RESP_NONE, "LIST () \"%s\" %s", delim, buf); | ||
59 | } | 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) | ... | ... |
-
Please register or sign in to post a comment