From: Timo Sirainen Date: Sat, 15 Nov 2008 19:10:17 +0000 (+0200) Subject: Moved imap-resp-codes to macros. X-Git-Tag: 1.2.alpha4~77 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=571c3f92f42194c440c161356c04687fc970ea11;p=thirdparty%2Fdovecot%2Fcore.git Moved imap-resp-codes to macros. --HG-- branch : HEAD --- diff --git a/src/imap-login/client-authenticate.c b/src/imap-login/client-authenticate.c index 3348942adf..f1a2c379c8 100644 --- a/src/imap-login/client-authenticate.c +++ b/src/imap-login/client-authenticate.c @@ -9,6 +9,7 @@ #include "safe-memset.h" #include "str.h" #include "str-sanitize.h" +#include "imap-resp-code.h" #include "imap-parser.h" #include "auth-client.h" #include "client.h" @@ -18,7 +19,7 @@ #include #define IMAP_SERVICE_NAME "imap" -#define IMAP_AUTH_FAILED_MSG "[AUTHENTICATIONFAILED] "AUTH_FAILED_MSG +#define IMAP_AUTH_FAILED_MSG "["IMAP_RESP_CODE_AUTHFAILED"] "AUTH_FAILED_MSG const char *client_authenticate_get_capabilities(bool secured) { @@ -180,7 +181,7 @@ static bool client_handle_args(struct imap_client *client, if (reason != NULL) str_printfa(reply, "NO %s", reason); else if (temp || proxy_self) { - str_append(reply, "NO [UNAVAILABLE] " + str_append(reply, "NO ["IMAP_RESP_CODE_UNAVAILABLE"] " AUTH_TEMP_FAILED_MSG); } else { str_append(reply, "NO "IMAP_AUTH_FAILED_MSG); @@ -337,7 +338,7 @@ int cmd_login(struct imap_client *client, const struct imap_arg *args) "* BAD [ALERT] Plaintext authentication is disabled, " "but your client sent password in plaintext anyway. " "If anyone was listening, the password was exposed."); - client_send_tagline(client, "NO [CLIENTBUG] " + client_send_tagline(client, "NO ["IMAP_RESP_CODE_CLIENTBUG"] " AUTH_PLAINTEXT_DISABLED_MSG); return 1; } diff --git a/src/imap/client.c b/src/imap/client.c index e2faa1719e..8a7c141f03 100644 --- a/src/imap/client.c +++ b/src/imap/client.c @@ -8,8 +8,9 @@ #include "istream.h" #include "ostream.h" #include "var-expand.h" -#include "commands.h" +#include "imap-resp-code.h" #include "mail-namespace.h" +#include "commands.h" #include #include @@ -409,7 +410,8 @@ static bool client_command_check_ambiguity(struct client_command_context *cmd) } if (broken_client) { - client_send_line(cmd->client, "* BAD [CLIENTBUG] " + client_send_line(cmd->client, + "* BAD ["IMAP_RESP_CODE_CLIENTBUG"] " "Command pipelining results in ambiguity."); } diff --git a/src/imap/cmd-copy.c b/src/imap/cmd-copy.c index 7b0148b7aa..75ab657683 100644 --- a/src/imap/cmd-copy.c +++ b/src/imap/cmd-copy.c @@ -3,6 +3,7 @@ #include "common.h" #include "str.h" #include "ostream.h" +#include "imap-resp-code.h" #include "commands.h" #include "imap-search.h" @@ -171,7 +172,8 @@ bool cmd_copy(struct client_command_context *cmd) return cmd_sync(cmd, sync_flags, imap_flags, msg); else if (ret == 0) { /* some messages were expunged, sync them */ - return cmd_sync(cmd, 0, 0, "NO [EXPUNGEISSUED] " + return cmd_sync(cmd, 0, 0, + "NO ["IMAP_RESP_CODE_EXPUNGEISSUED"] " "Some of the requested messages no longer exist."); } else { client_send_storage_error(cmd, storage); diff --git a/src/imap/cmd-fetch.c b/src/imap/cmd-fetch.c index 44f4a78318..eeb02f870a 100644 --- a/src/imap/cmd-fetch.c +++ b/src/imap/cmd-fetch.c @@ -2,6 +2,7 @@ #include "common.h" #include "ostream.h" +#include "imap-resp-code.h" #include "commands.h" #include "imap-fetch.h" #include "imap-search.h" @@ -132,7 +133,7 @@ static bool cmd_fetch_finish(struct imap_fetch_context *ctx) static const char *ok_message = "OK Fetch completed."; if (ctx->partial_fetch) { - ok_message = "OK [EXPUNGEISSUED] " + ok_message = "OK ["IMAP_RESP_CODE_EXPUNGEISSUED"] " "Some messages were already expunged."; } diff --git a/src/imap/cmd-search.c b/src/imap/cmd-search.c index e696f19269..e77d521df0 100644 --- a/src/imap/cmd-search.c +++ b/src/imap/cmd-search.c @@ -4,11 +4,12 @@ #include "ostream.h" #include "str.h" #include "seq-range-array.h" -#include "commands.h" -#include "mail-search-build.h" +#include "imap-resp-code.h" #include "imap-quote.h" #include "imap-seqset.h" #include "imap-util.h" +#include "mail-search-build.h" +#include "commands.h" #include "imap-search.h" enum search_return_options { @@ -366,6 +367,7 @@ static bool cmd_search_more(struct client_command_context *cmd) const struct seq_range *range; unsigned int count; uint32_t id, id_min, id_max; + const char *ok_reply; bool tryagain, minmax, lost_data; if (cmd->cancel) { @@ -459,11 +461,10 @@ static bool cmd_search_more(struct client_command_context *cmd) sync_flags = MAILBOX_SYNC_FLAG_FAST; if (!cmd->uid || ctx->have_seqsets) sync_flags |= MAILBOX_SYNC_FLAG_NO_EXPUNGES; - return cmd_sync(cmd, sync_flags, 0, - t_strdup_printf("OK %sSearch completed (%d.%03d secs).", - lost_data ? "[EXPUNGEISSUED] " : "", - (int)end_time.tv_sec, - (int)(end_time.tv_usec/1000))); + ok_reply = t_strdup_printf("OK %sSearch completed (%d.%03d secs).", + lost_data ? "["IMAP_RESP_CODE_EXPUNGEISSUED"] " : "", + (int)end_time.tv_sec, (int)(end_time.tv_usec/1000)); + return cmd_sync(cmd, sync_flags, 0, ok_reply); } static void cmd_search_more_callback(struct client_command_context *cmd) diff --git a/src/imap/cmd-status.c b/src/imap/cmd-status.c index 94581910e7..d0ac319a12 100644 --- a/src/imap/cmd-status.c +++ b/src/imap/cmd-status.c @@ -1,6 +1,7 @@ /* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */ #include "common.h" +#include "imap-resp-code.h" #include "commands.h" #include "imap-sync.h" #include "imap-status.h" @@ -45,7 +46,7 @@ bool cmd_status(struct client_command_context *cmd) if (!selected_mailbox) client_send_tagline(cmd, "OK Status completed."); else { - client_send_tagline(cmd, "OK [CLIENTBUG] " + client_send_tagline(cmd, "OK ["IMAP_RESP_CODE_CLIENTBUG"] " "Status on selected mailbox completed."); } return TRUE; diff --git a/src/imap/commands-util.c b/src/imap/commands-util.c index 535a7654c6..2a947dd84a 100644 --- a/src/imap/commands-util.c +++ b/src/imap/commands-util.c @@ -5,12 +5,13 @@ #include "buffer.h" #include "str.h" #include "str-sanitize.h" -#include "mail-storage.h" -#include "commands-util.h" +#include "imap-resp-code.h" #include "imap-parser.h" #include "imap-sync.h" #include "imap-util.h" +#include "mail-storage.h" #include "mail-namespace.h" +#include "commands-util.h" /* Maximum length for mailbox name, including it's path. This isn't fully exact since the user can create folder hierarchy with small names, then @@ -152,29 +153,29 @@ get_error_string(const char *error_string, enum mail_error error) case MAIL_ERROR_NONE: break; case MAIL_ERROR_TEMP: - resp_code = "SERVERBUG"; + resp_code = IMAP_RESP_CODE_SERVERBUG; break; case MAIL_ERROR_NOTPOSSIBLE: case MAIL_ERROR_PARAMS: - resp_code = "CANNOT"; + resp_code = IMAP_RESP_CODE_CANNOT; break; case MAIL_ERROR_PERM: - resp_code = "ACL"; + resp_code = IMAP_RESP_CODE_ACL; break; case MAIL_ERROR_NOSPACE: - resp_code = "OVERQUOTA"; + resp_code = IMAP_RESP_CODE_OVERQUOTA; break; case MAIL_ERROR_NOTFOUND: - resp_code = "NONEXISTENT"; + resp_code = IMAP_RESP_CODE_NONEXISTENT; break; case MAIL_ERROR_EXISTS: - resp_code = "ALREADYEXISTS"; + resp_code = IMAP_RESP_CODE_ALREADYEXISTS; break; case MAIL_ERROR_EXPUNGED: - resp_code = "EXPUNGEISSUED"; + resp_code = IMAP_RESP_CODE_EXPUNGEISSUED; break; case MAIL_ERROR_INUSE: - resp_code = "INUSE"; + resp_code = IMAP_RESP_CODE_INUSE; break; } if (resp_code == NULL || *error_string == '[') diff --git a/src/lib-imap/Makefile.am b/src/lib-imap/Makefile.am index 459f468d7f..61d66638e5 100644 --- a/src/lib-imap/Makefile.am +++ b/src/lib-imap/Makefile.am @@ -26,6 +26,7 @@ headers = \ imap-id.h \ imap-match.h \ imap-parser.h \ + imap-resp-code.h \ imap-quote.h \ imap-seqset.h \ imap-utf7.h \ diff --git a/src/lib-imap/imap-resp-code.h b/src/lib-imap/imap-resp-code.h new file mode 100644 index 0000000000..9cf8cccce8 --- /dev/null +++ b/src/lib-imap/imap-resp-code.h @@ -0,0 +1,22 @@ +#ifndef IMAP_RESP_CODE_H +#define IMAP_RESP_CODE_H + +/* IMAP response codes (from draft-gulbrandsen-imap-response-codes-04) */ +#define IMAP_RESP_CODE_UNAVAILABLE "UNAVAILABLE" +#define IMAP_RESP_CODE_AUTHFAILED "AUTHENTICATIONFAILED" +#define IMAP_RESP_CODE_AUTHZFAILED "AUTHORIZATIONFAILED" +#define IMAP_RESP_CODE_EXPIRED "EXPIRED" +#define IMAP_RESP_CODE_CONTACTADMIN "CONTACTADMIN" +#define IMAP_RESP_CODE_ACL "ACL" +#define IMAP_RESP_CODE_INUSE "INUSE" +#define IMAP_RESP_CODE_EXPUNGEISSUED "EXPUNGEISSUED" +#define IMAP_RESP_CODE_CORRUPTION "CORRUPTION" +#define IMAP_RESP_CODE_SERVERBUG "SERVERBUG" +#define IMAP_RESP_CODE_CLIENTBUG "CLIENTBUG" +#define IMAP_RESP_CODE_CANNOT "CANNOT" +#define IMAP_RESP_CODE_LIMIT "LIMIT" +#define IMAP_RESP_CODE_OVERQUOTA "OVERQUOTA" +#define IMAP_RESP_CODE_ALREADYEXISTS "ALREADYEXISTS" +#define IMAP_RESP_CODE_NONEXISTENT "NONEXISTENT" + +#endif