Select now fails if the locking fails.
Showing
2 changed files
with
27 additions
and
16 deletions
... | @@ -169,7 +169,7 @@ extern int imap4d_search __P ((struct imap4d_command *, char *)); | ... | @@ -169,7 +169,7 @@ extern int imap4d_search __P ((struct imap4d_command *, char *)); |
169 | extern int imap4d_search0 __P((char *arg, int isuid, char *replybuf, size_t replysize)); | 169 | extern int imap4d_search0 __P((char *arg, int isuid, char *replybuf, size_t replysize)); |
170 | extern int imap4d_select __P ((struct imap4d_command *, char *)); | 170 | extern int imap4d_select __P ((struct imap4d_command *, char *)); |
171 | extern int imap4d_select0 __P ((struct imap4d_command *, char *, int)); | 171 | extern int imap4d_select0 __P ((struct imap4d_command *, char *, int)); |
172 | extern void imap4d_select_status __P((void)); | 172 | extern int imap4d_select_status __P((void)); |
173 | extern int imap4d_status __P ((struct imap4d_command *, char *)); | 173 | extern int imap4d_status __P ((struct imap4d_command *, char *)); |
174 | extern int imap4d_store __P ((struct imap4d_command *, char *)); | 174 | extern int imap4d_store __P ((struct imap4d_command *, char *)); |
175 | extern int imap4d_store0 __P ((char *, int, char *, size_t)); | 175 | extern int imap4d_store0 __P ((char *, int, char *, size_t)); | ... | ... |
... | @@ -80,44 +80,52 @@ imap4d_select0 (struct imap4d_command *command, char *arg, int flags) | ... | @@ -80,44 +80,52 @@ imap4d_select0 (struct imap4d_command *command, char *arg, int flags) |
80 | if (!mailbox_name) | 80 | if (!mailbox_name) |
81 | return util_finish (command, RESP_NO, "Couldn't open mailbox"); | 81 | return util_finish (command, RESP_NO, "Couldn't open mailbox"); |
82 | 82 | ||
83 | if (mailbox_create (&mbox, mailbox_name) == 0 | 83 | if ((status = mailbox_create (&mbox, mailbox_name)) == 0 |
84 | && mailbox_open (mbox, flags) == 0) | 84 | && (status = mailbox_open (mbox, flags)) == 0 |
85 | ) | ||
85 | { | 86 | { |
86 | free (mailbox_name); | ||
87 | select_flags = flags; | 87 | select_flags = flags; |
88 | state = STATE_SEL; | 88 | state = STATE_SEL; |
89 | imap4d_select_status(); | 89 | if ((status = imap4d_select_status ()) == 0) |
90 | { | ||
91 | free (mailbox_name); | ||
90 | /* Need to set the state explicitely for select. */ | 92 | /* Need to set the state explicitely for select. */ |
91 | return util_send ("%s OK [%s] %s Completed\r\n", command->tag, | 93 | return util_send ("%s OK [%s] %s Completed\r\n", command->tag, |
92 | (MU_STREAM_READ == flags) ? | 94 | (MU_STREAM_READ == flags) ? |
93 | "READ-ONLY" : "READ-WRITE", command->name); | 95 | "READ-ONLY" : "READ-WRITE", command->name); |
94 | } | 96 | } |
95 | status = util_finish (command, RESP_NO, "Couldn't open %s", mailbox_name); | 97 | } |
98 | status = util_finish (command, RESP_NO, "Couldn't open %s, %s", | ||
99 | mailbox_name, mu_errstring (status)); | ||
96 | free (mailbox_name); | 100 | free (mailbox_name); |
97 | return status; | 101 | return status; |
98 | } | 102 | } |
99 | 103 | ||
100 | /* The code is shared between select and noop */ | 104 | /* The code is shared between select and noop */ |
101 | void | 105 | int |
102 | imap4d_select_status() | 106 | imap4d_select_status () |
103 | { | 107 | { |
104 | const char *mflags = "\\Answered \\Flagged \\Deleted \\Seen \\Draft"; | 108 | const char *mflags = "\\Answered \\Flagged \\Deleted \\Seen \\Draft"; |
105 | const char *pflags = "\\Answered \\Deleted \\Seen"; | 109 | const char *pflags = "\\Answered \\Deleted \\Seen"; |
106 | unsigned long uidvalidity = 0; | 110 | unsigned long uidvalidity = 0; |
107 | size_t count = 0, recent = 0, unseen = 0, uidnext = 0; | 111 | size_t count = 0, recent = 0, unseen = 0, uidnext = 0; |
112 | int status = 0; | ||
108 | 113 | ||
109 | if (state != STATE_SEL) | 114 | if (state != STATE_SEL) |
110 | return; | 115 | return 0; /* FIXME: this should be something! */ |
116 | |||
117 | if ( | ||
118 | (status = mailbox_uidvalidity (mbox, &uidvalidity)) || | ||
119 | (status = mailbox_uidnext (mbox, &uidnext)) || | ||
120 | (status = mailbox_messages_count (mbox, &count)) || | ||
121 | (status = mailbox_messages_recent (mbox, &recent)) || | ||
122 | (status = mailbox_message_unseen (mbox, &unseen)) | ||
123 | ) | ||
124 | return status; | ||
111 | 125 | ||
112 | mailbox_uidvalidity (mbox, &uidvalidity); | ||
113 | mailbox_uidnext (mbox, &uidnext); | ||
114 | mailbox_messages_count (mbox, &count); | ||
115 | mailbox_messages_recent (mbox, &recent); | ||
116 | mailbox_message_unseen (mbox, &unseen); | ||
117 | util_out (RESP_NONE, "%d EXISTS", count); | 126 | util_out (RESP_NONE, "%d EXISTS", count); |
118 | util_out (RESP_NONE, "%d RECENT", recent); | 127 | util_out (RESP_NONE, "%d RECENT", recent); |
119 | util_out (RESP_OK, "[UIDVALIDITY %d] UID valididy status", | 128 | util_out (RESP_OK, "[UIDVALIDITY %d] UID valididy status", uidvalidity); |
120 | uidvalidity); | ||
121 | util_out (RESP_OK, "[UIDNEXT %d] Predicted next uid", uidnext); | 129 | util_out (RESP_OK, "[UIDNEXT %d] Predicted next uid", uidnext); |
122 | if (unseen) | 130 | if (unseen) |
123 | util_out (RESP_OK, "[UNSEEN %d] first unseen messsage ", unseen); | 131 | util_out (RESP_OK, "[UNSEEN %d] first unseen messsage ", unseen); |
... | @@ -129,4 +137,7 @@ imap4d_select_status() | ... | @@ -129,4 +137,7 @@ imap4d_select_status() |
129 | util_out (RESP_OK, "[PERMANENTFLAGS ()] No Permanent flags"); | 137 | util_out (RESP_OK, "[PERMANENTFLAGS ()] No Permanent flags"); |
130 | else | 138 | else |
131 | util_out (RESP_OK, "[PERMANENTFLAGS (%s)] Permanent flags", pflags); | 139 | util_out (RESP_OK, "[PERMANENTFLAGS (%s)] Permanent flags", pflags); |
140 | |||
141 | return 0; | ||
132 | } | 142 | } |
143 | ... | ... |
-
Please register or sign in to post a comment