Commit 425d200a 425d200a1eee0b7b279711de92c4dd061efd6033 by Sergey Poznyakoff

Provide better diagnostics.

1 parent 72d25ce5
...@@ -62,7 +62,8 @@ imap4d_status (struct imap4d_command *command, char *arg) ...@@ -62,7 +62,8 @@ imap4d_status (struct imap4d_command *command, char *arg)
62 mailbox_t smbox = NULL; 62 mailbox_t smbox = NULL;
63 int status; 63 int status;
64 int count = 0; 64 int count = 0;
65 65 char *err_msg = NULL;
66
66 if (! (command->states & state)) 67 if (! (command->states & state))
67 return util_finish (command, RESP_BAD, "Wrong state"); 68 return util_finish (command, RESP_BAD, "Wrong state");
68 69
...@@ -76,13 +77,14 @@ imap4d_status (struct imap4d_command *command, char *arg) ...@@ -76,13 +77,14 @@ imap4d_status (struct imap4d_command *command, char *arg)
76 struct passwd *pw = mu_getpwuid (getuid()); 77 struct passwd *pw = mu_getpwuid (getuid());
77 if (!pw) 78 if (!pw)
78 return util_finish (command, RESP_NO, "Cannot map UID to username"); 79 return util_finish (command, RESP_NO, "Cannot map UID to username");
79 mailbox_name = malloc (strlen (maildir) + strlen (pw->pw_name) + 1); 80 mailbox_name = malloc (strlen (mu_path_maildir) +
81 strlen (pw->pw_name) + 1);
80 if (!mailbox_name) 82 if (!mailbox_name)
81 { 83 {
82 syslog (LOG_ERR, "Not enough memory"); 84 syslog (LOG_ERR, "Not enough memory");
83 return util_finish (command, RESP_NO, "Not enough memory"); 85 return util_finish (command, RESP_NO, "Not enough memory");
84 } 86 }
85 sprintf (mailbox_name, "%s%s", maildir, pw->pw_name); 87 sprintf (mailbox_name, "%s%s", mu_path_maildir, pw->pw_name);
86 } 88 }
87 else 89 else
88 mailbox_name = namespace_getfullpath (name, delim); 90 mailbox_name = namespace_getfullpath (name, delim);
...@@ -113,7 +115,7 @@ imap4d_status (struct imap4d_command *command, char *arg) ...@@ -113,7 +115,7 @@ imap4d_status (struct imap4d_command *command, char *arg)
113 fun = status_get_handler (item); 115 fun = status_get_handler (item);
114 if (!fun) 116 if (!fun)
115 { 117 {
116 count = -1; 118 err_msg = "Invalid flag in list";
117 break; 119 break;
118 } 120 }
119 121
...@@ -123,7 +125,7 @@ imap4d_status (struct imap4d_command *command, char *arg) ...@@ -123,7 +125,7 @@ imap4d_status (struct imap4d_command *command, char *arg)
123 if (!fun (smbox)) 125 if (!fun (smbox))
124 util_send (" "); 126 util_send (" ");
125 } 127 }
126 if (count) 128 if (count > 0)
127 util_send (")\r\n"); 129 util_send (")\r\n");
128 mailbox_close (smbox); 130 mailbox_close (smbox);
129 } 131 }
...@@ -131,12 +133,15 @@ imap4d_status (struct imap4d_command *command, char *arg) ...@@ -131,12 +133,15 @@ imap4d_status (struct imap4d_command *command, char *arg)
131 } 133 }
132 free (mailbox_name); 134 free (mailbox_name);
133 135
134 if (count == 0) 136 if (status == 0)
135 return util_finish (command, RESP_BAD, "Too few args (empty list)"); 137 {
136 else if (count == -1) 138 if (count == 0)
137 return util_finish (command, RESP_BAD, "Invalid flag in list"); 139 return util_finish (command, RESP_BAD, "Too few args (empty list)");
138 else if (status == 0) 140 else if (err_msg)
139 return util_finish (command, RESP_OK, "Completed"); 141 return util_finish (command, RESP_BAD, err_msg);
142 return util_finish (command, RESP_OK, "Completed");
143 }
144
140 return util_finish (command, RESP_NO, "Error opening mailbox"); 145 return util_finish (command, RESP_NO, "Error opening mailbox");
141 } 146 }
142 147
......