1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 /* Include files we are going to want available to all files....these files
7    include NSPR, memory, and string header files among others */
8 
9 #ifndef msgCore_h__
10 #define msgCore_h__
11 
12 #include "nscore.h"
13 #include "nspr.h"
14 #include "plstr.h"
15 #include "nsCRTGlue.h"
16 
17 class nsIMsgDBHdr;
18 class nsIMsgFolder;
19 
20 // include common interfaces such as the service manager and the repository....
21 #include "nsIServiceManager.h"
22 #include "nsIComponentManager.h"
23 
24 /*
25  * The suffix we use for the mail summary file.
26  */
27 #define SUMMARY_SUFFIX u".msf"
28 #define SUMMARY_SUFFIX8 ".msf"
29 #define SUMMARY_SUFFIX_LENGTH 4
30 
31 /*
32  * The suffix we use for folder subdirectories.
33  */
34 #define FOLDER_SUFFIX u".sbd"
35 #define FOLDER_SUFFIX8 ".sbd"
36 #define FOLDER_SUFFIX_LENGTH 4
37 
38 /*
39  * These are folder property strings, which are used in several places.
40 
41  */
42 // Most recently used (opened, moved to, got new messages)
43 #define MRU_TIME_PROPERTY "MRUTime"
44 // Most recently moved to, for recent folders list in move menu
45 #define MRM_TIME_PROPERTY "MRMTime"
46 
47 /* NS_ERROR_MODULE_MAILNEWS is defined in mozilla/xpcom/public/nsError.h */
48 
49 /*
50  * NS_ERROR macros - use these macros to generate error constants
51  * to be used by XPCOM interfaces and possibly other useful things
52  * do not use these macros in your code - declare error macros for
53  * each specific error you need.
54  *
55  * for example:
56  * #define NS_MSG_ERROR_NO_SUCH_FOLDER NS_MSG_GENERATE_FAILURE(4)
57  *
58  */
59 
60 /* use these routines to generate error values */
61 #define NS_MSG_GENERATE_RESULT(severity, value) \
62   NS_ERROR_GENERATE(severity, NS_ERROR_MODULE_MAILNEWS, value)
63 
64 #define NS_MSG_GENERATE_SUCCESS(value) \
65   NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_MAILNEWS, value)
66 
67 #define NS_MSG_GENERATE_FAILURE(value) \
68   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_MAILNEWS, value)
69 
70 /* these are shortcuts to generate simple errors with a zero value */
71 #define NS_MSG_SUCCESS NS_MSG_GENERATE_SUCCESS(0)
72 #define NS_MSG_FAILURE NS_MSG_GENERATE_FAILURE(0)
73 
74 #define IS_SPACE(VAL) \
75   (((((PRIntn)(VAL)) & 0x7f) == ((PRIntn)(VAL))) && isspace((PRIntn)(VAL)))
76 
77 #define IS_DIGIT(i) ((((unsigned int)(i)) > 0x7f) ? (int)0 : isdigit(i))
78 #if defined(XP_WIN)
79 #  define IS_ALPHA(VAL) (isascii((int)(VAL)) && isalpha((int)(VAL)))
80 #else
81 #  define IS_ALPHA(VAL) \
82     ((((unsigned int)(VAL)) > 0x7f) ? (int)0 : isalpha((int)(VAL)))
83 #endif
84 
85 /* for retrieving information out of messenger nsresults */
86 
87 #define NS_IS_MSG_ERROR(err) \
88   (NS_ERROR_GET_MODULE(err) == NS_ERROR_MODULE_MAILNEWS)
89 
90 #define NS_MSG_SUCCEEDED(err) (NS_IS_MSG_ERROR(err) && NS_SUCCEEDED(err))
91 
92 #define NS_MSG_FAILED(err) (NS_IS_MSG_ERROR(err) && NS_FAILED(err))
93 
94 #define NS_MSG_PASSWORD_PROMPT_CANCELLED NS_MSG_GENERATE_SUCCESS(1)
95 
96 /**
97  * Indicates that a search is done/terminated because it was interrupted.
98  * Interrupting a search originally notified listeners with
99  * OnSearchDone(NS_OK), so we define a success value to continue doing this,
100  * and because the search was fine except for an explicit call to interrupt it.
101  */
102 #define NS_MSG_SEARCH_INTERRUPTED NS_MSG_GENERATE_SUCCESS(2)
103 
104 /* This is where we define our errors. There has to be a central
105    place so we don't use the same error codes for different errors.
106 */
107 #define NS_MSG_ERROR_FOLDER_SUMMARY_OUT_OF_DATE NS_MSG_GENERATE_FAILURE(5)
108 #define NS_MSG_ERROR_FOLDER_SUMMARY_MISSING NS_MSG_GENERATE_FAILURE(6)
109 #define NS_MSG_ERROR_FOLDER_MISSING NS_MSG_GENERATE_FAILURE(7)
110 
111 #define NS_MSG_MESSAGE_NOT_FOUND NS_MSG_GENERATE_FAILURE(8)
112 #define NS_MSG_NOT_A_MAIL_FOLDER NS_MSG_GENERATE_FAILURE(9)
113 
114 #define NS_MSG_FOLDER_BUSY NS_MSG_GENERATE_FAILURE(10)
115 
116 #define NS_MSG_COULD_NOT_CREATE_DIRECTORY NS_MSG_GENERATE_FAILURE(11)
117 #define NS_MSG_CANT_CREATE_FOLDER NS_MSG_GENERATE_FAILURE(12)
118 
119 #define NS_MSG_FILTER_PARSE_ERROR NS_MSG_GENERATE_FAILURE(13)
120 
121 #define NS_MSG_FOLDER_UNREADABLE NS_MSG_GENERATE_FAILURE(14)
122 
123 #define NS_MSG_ERROR_WRITING_MAIL_FOLDER NS_MSG_GENERATE_FAILURE(15)
124 
125 #define NS_MSG_ERROR_NO_SEARCH_VALUES NS_MSG_GENERATE_FAILURE(16)
126 
127 #define NS_MSG_ERROR_INVALID_SEARCH_SCOPE NS_MSG_GENERATE_FAILURE(17)
128 
129 #define NS_MSG_ERROR_INVALID_SEARCH_TERM NS_MSG_GENERATE_FAILURE(18)
130 
131 #define NS_MSG_FOLDER_EXISTS NS_MSG_GENERATE_FAILURE(19)
132 
133 #define NS_MSG_ERROR_OFFLINE NS_MSG_GENERATE_FAILURE(20)
134 
135 #define NS_MSG_POP_FILTER_TARGET_ERROR NS_MSG_GENERATE_FAILURE(21)
136 
137 #define NS_MSG_INVALID_OR_MISSING_SERVER NS_MSG_GENERATE_FAILURE(22)
138 
139 #define NS_MSG_SERVER_USERNAME_MISSING NS_MSG_GENERATE_FAILURE(23)
140 
141 #define NS_MSG_INVALID_DBVIEW_INDEX NS_MSG_GENERATE_FAILURE(24)
142 
143 #define NS_MSG_NEWS_ARTICLE_NOT_FOUND NS_MSG_GENERATE_FAILURE(25)
144 
145 #define NS_MSG_ERROR_COPY_FOLDER_ABORTED NS_MSG_GENERATE_FAILURE(26)
146 // this error means a url was queued but never run because one of the urls
147 // it was queued after failed. We send an OnStopRunningUrl with this error code
148 // so the listeners can know that we didn't run the url.
149 #define NS_MSG_ERROR_URL_ABORTED NS_MSG_GENERATE_FAILURE(27)
150 
151 // when num of custom headers exceeds 50
152 #define NS_MSG_CUSTOM_HEADERS_OVERFLOW NS_MSG_GENERATE_FAILURE(28)
153 
154 // when custom header has invalid characters (as per rfc 2822)
155 #define NS_MSG_INVALID_CUSTOM_HEADER NS_MSG_GENERATE_FAILURE(29)
156 
157 // when local caches are password protect and user isn't auth
158 #define NS_MSG_USER_NOT_AUTHENTICATED NS_MSG_GENERATE_FAILURE(30)
159 
160 #define NS_MSG_ERROR_COPYING_FROM_TMP_DOWNLOAD \
161   NS_MSG_GENERATE_FAILURE(31)  // pop3 downloaded to tmp file, and failed.
162 
163 // The code tried to stream a message using the aLocalOnly argument, but
164 // the message was not cached locally.
165 #define NS_MSG_ERROR_MSG_NOT_OFFLINE NS_MSG_GENERATE_FAILURE(32)
166 
167 // The imap server returned NO or BAD for an IMAP command
168 #define NS_MSG_ERROR_IMAP_COMMAND_FAILED NS_MSG_GENERATE_FAILURE(33)
169 
170 #define NS_MSG_ERROR_INVALID_FOLDER_NAME NS_MSG_GENERATE_FAILURE(34)
171 
172 /* Error codes for message compose are defined in
173    compose\src\nsMsgComposeStringBundle.h. Message compose use the same error
174    code space as other mailnews modules. To avoid any conflict, values between
175    12500 and 12999 are reserved.
176 */
177 #define NS_MSGCOMP_ERROR_BEGIN 12500
178 /* NS_ERROR_NNTP_NO_CROSS_POSTING lives here, and not in
179  * nsMsgComposeStringBundle.h, because it is used in news and compose. */
180 #define NS_ERROR_NNTP_NO_CROSS_POSTING NS_MSG_GENERATE_FAILURE(12554)
181 #define NS_MSGCOMP_ERROR_END 12999
182 
183 #if defined(XP_WIN)
184 #  define MSG_LINEBREAK "\015\012"
185 #  define MSG_LINEBREAK_LEN 2
186 #else
187 #  define MSG_LINEBREAK "\012"
188 #  define MSG_LINEBREAK_LEN 1
189 #endif
190 
191 /*
192  * On Windows, we use \r\n as the line terminator in mbox files. On
193  * other platforms, we use \n. However, we need to be able to
194  * recognize line terminators produced on any platform, because we
195  * allow profiles (including the mbox files they contain) to be shared
196  * between platforms.
197  *
198  * Returns 0 (i.e., false) if the line is not blank, or otherwise the
199  * length of the line terminator, i.e., 1 for \n or 2 for \r\n.
200  */
201 #define IS_MSG_LINEBREAK(line) \
202   (line[0] == '\012' ? 1 : ((line[0] == '\015' && line[1] == '\012') ? 2 : 0))
203 
204 #define NS_MSG_BASE
205 #define NS_MSG_BASE_STATIC_MEMBER_(type) type
206 
207 /// The number of microseconds in a day. This comes up a lot.
208 #define PR_USEC_PER_DAY (PRTime(PR_USEC_PER_SEC) * 60 * 60 * 24)
209 
210 #endif  // msgCore_h__
211