Colorize collapsed threads based on aggregated tags
[trojita.git] / src / Imap / Exceptions.h
blob701e5375a8569a8282eeb24fc4e5640ec843f698
1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef IMAP_EXCEPTIONS_H
23 #define IMAP_EXCEPTIONS_H
24 #include <exception>
25 #include <string>
26 #include <QByteArray>
28 /**
29 * @file
30 * @short Common IMAP-related exceptions
32 * All IMAP-related exceptions inherit from Imap::Exception which inherits from
33 * std::exception.
35 * @author Jan Kundrát <jkt@flaska.net>
38 /** @short Namespace for IMAP interaction */
39 namespace Imap
42 namespace Responses
44 class AbstractResponse;
47 /** @short General exception class */
48 class ImapException : public std::exception
50 protected:
51 /** The error message */
52 std::string m_msg;
53 /** Line with data that caused this error */
54 QByteArray m_line;
55 /** Offset in line for error source */
56 int m_offset;
57 /** Class name of the exception */
58 std::string m_exceptionClass;
59 public:
60 ImapException(): m_offset(-1), m_exceptionClass("ImapException") {}
61 ImapException(const std::string &msg) : m_msg(msg), m_offset(-1), m_exceptionClass("ImapException") {};
62 ImapException(const std::string &msg, const QByteArray &line, const int offset):
63 m_msg(msg), m_line(line), m_offset(offset), m_exceptionClass("ImapException") {};
64 virtual const char *what() const throw();
65 virtual ~ImapException() throw() {};
66 std::string msg() const { return m_msg; }
67 QByteArray line() const { return m_line; }
68 int offset() const { return m_offset; }
69 std::string exceptionClass() const { return m_exceptionClass; }
72 #define ECBODY(CLASSNAME, PARENT) class CLASSNAME: public PARENT { \
73 public: CLASSNAME(const std::string &msg): PARENT(msg) { m_exceptionClass = #CLASSNAME; }\
74 CLASSNAME(const QByteArray &line, const int offset): PARENT(#CLASSNAME, line, offset) { m_exceptionClass = #CLASSNAME; }\
75 CLASSNAME(const std::string &msg, const QByteArray &line, const int offset): PARENT(msg, line, offset) { m_exceptionClass = #CLASSNAME; }\
78 /** @short A generic parser exception */
79 ECBODY(ParserException, ImapException)
81 /** @short Invalid argument was passed to some function */
82 ECBODY(InvalidArgument, ParserException)
84 /** @short General parse error */
85 ECBODY(ParseError, ParserException)
87 /** @short Parse error: unknown identifier */
88 ECBODY(UnknownIdentifier, ParseError)
90 /** @short Parse error: unrecognized kind of response */
91 ECBODY(UnrecognizedResponseKind, UnknownIdentifier)
93 /** @short Parse error: this is known, but not expected here */
94 ECBODY(UnexpectedHere, ParseError)
96 /** @short Parse error: No usable data */
97 ECBODY(NoData, ParseError)
99 /** @short Parse error: Too much data */
100 ECBODY(TooMuchData, ParseError)
102 /** @short Command Continuation Request received, but we have no idea how to handle it here */
103 ECBODY(ContinuationRequest, ParserException)
105 /** @short Invalid Response Code */
106 ECBODY(InvalidResponseCode, ParseError)
108 /** @short This is not an IMAP4 server */
109 ECBODY(NotAnImapServerError, ParseError)
111 #undef ECBODY
113 /** @short Parent for all exceptions thrown by Imap::Mailbox-related classes */
114 class MailboxException: public ImapException
116 public:
117 MailboxException(const char *const msg, const Imap::Responses::AbstractResponse &response);
118 explicit MailboxException(const char *const msg);
119 virtual const char *what() const throw() { return m_msg.c_str(); }
120 virtual ~MailboxException() throw() {}
124 #define ECBODY(CLASSNAME, PARENT) class CLASSNAME: public PARENT { \
125 public: CLASSNAME(const char *const msg, const Imap::Responses::AbstractResponse &response): PARENT(msg, response) { m_exceptionClass=#CLASSNAME; } \
126 CLASSNAME(const char *const msg): PARENT(msg) { m_exceptionClass=#CLASSNAME; } \
129 /** @short Server sent us something that isn't expected right now */
130 ECBODY(UnexpectedResponseReceived, MailboxException)
132 /** @short Internal error in Imap::Mailbox code -- there must be bug in its code */
133 ECBODY(CantHappen, MailboxException)
135 /** @short Server sent us information about message we don't know */
136 ECBODY(UnknownMessageIndex, MailboxException)
138 #undef ECBODY
141 #endif /* IMAP_EXCEPTIONS_H */