Back to index

lightning-sunbird  0.9+nobinonly
nsMsgUtils.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _NSMSGUTILS_H
00039 #define _NSMSGUTILS_H
00040 
00041 #include "nsIURL.h"
00042 #include "nsString.h"
00043 #include "nsIEnumerator.h"
00044 #include "msgCore.h"
00045 #include "nsCOMPtr.h"
00046 #include "MailNewsTypes2.h"
00047 
00048 class nsIFileSpec;
00049 class nsILocalFile;
00050 class nsIPrefBranch;
00051 class nsIMsgFolder;
00052 class nsIMsgMessageService;
00053 class nsIUrlListener;
00054 
00055 //These are utility functions that can used throughout the mailnews code
00056 
00057 NS_MSG_BASE nsresult GetMessageServiceContractIDForURI(const char *uri, nsCString &contractID);
00058 
00059 NS_MSG_BASE nsresult GetMessageServiceFromURI(const char *uri, nsIMsgMessageService **aMessageService);
00060 
00061 NS_MSG_BASE nsresult GetMsgDBHdrFromURI(const char *uri, nsIMsgDBHdr **msgHdr);
00062 
00063 NS_MSG_BASE nsresult CreateStartupUrl(const char *uri, nsIURI** aUrl);
00064 
00065 NS_MSG_BASE nsresult NS_MsgGetPriorityFromString(
00066                        const char * const priority,
00067                        nsMsgPriorityValue & outPriority);
00068 
00069 NS_MSG_BASE nsresult NS_MsgGetPriorityValueString(
00070                        const nsMsgPriorityValue p,
00071                        nsACString & outValueString);
00072 
00073 NS_MSG_BASE nsresult NS_MsgGetUntranslatedPriorityName(
00074                        const nsMsgPriorityValue p,
00075                        nsACString & outName);
00076 
00077 NS_MSG_BASE nsresult NS_MsgHashIfNecessary(nsAutoString &name);
00078 NS_MSG_BASE nsresult NS_MsgHashIfNecessary(nsCAutoString &name);
00079 
00080 NS_MSG_BASE nsresult NS_MsgCreatePathStringFromFolderURI(const char *aFolderURI, 
00081                                                          nsCString& aPathString,
00082                                                          PRBool aIsNewsFolder=PR_FALSE);
00083 
00084 NS_MSG_BASE PRBool NS_MsgStripRE(const char **stringP, PRUint32 *lengthP, char **modifiedSubject=nsnull);
00085 
00086 NS_MSG_BASE char * NS_MsgSACopy(char **destination, const char *source);
00087 
00088 NS_MSG_BASE char * NS_MsgSACat(char **destination, const char *source);
00089 
00090 NS_MSG_BASE nsresult NS_MsgEscapeEncodeURLPath(const nsAString& aStr,
00091                                                nsAFlatCString& aResult);
00092 
00093 NS_MSG_BASE nsresult NS_MsgDecodeUnescapeURLPath(const nsACString& aPath,
00094                                                  nsAString& aResult);
00095 
00096 NS_MSG_BASE PRBool WeAreOffline();
00097 
00098 // Check if a folder with aFolderUri exists
00099 NS_MSG_BASE nsresult GetExistingFolder(const char *aFolderURI, nsIMsgFolder **aFolder);
00100 
00101 // Escape lines starting with "From ", ">From ", etc. in a buffer.
00102 NS_MSG_BASE nsresult EscapeFromSpaceLine(nsIFileSpec *pDst, char *start, const char *end);
00103 NS_MSG_BASE PRBool IsAFromSpaceLine(char *start, const char *end);
00104 
00105 NS_MSG_BASE nsresult NS_GetPersistentFile(const char *relPrefName,
00106                                           const char *absPrefName,
00107                                           const char *dirServiceProp, // Can be NULL
00108                                           PRBool& gotRelPref,
00109                                           nsILocalFile **aFile);
00110 
00111 NS_MSG_BASE nsresult NS_SetPersistentFile(const char *relPrefName,
00112                                           const char *absPrefName,
00113                                           nsILocalFile *aFile);
00114 
00115 NS_MSG_BASE nsresult CreateServicesForPasswordManager();
00116 
00117 NS_MSG_BASE nsresult IsRFC822HeaderFieldName(const char *aHdr, PRBool *aResult);
00118 
00119 NS_MSG_BASE nsresult NS_GetUnicharPreferenceWithDefault(nsIPrefBranch *prefBranch,   //can be null, if so uses the root branch
00120                                                         const char *prefName,
00121                                                         const nsString& defValue,
00122                                                         nsString& prefValue);
00123  
00124 NS_MSG_BASE nsresult NS_GetLocalizedUnicharPreferenceWithDefault(nsIPrefBranch *prefBranch,   //can be null, if so uses the root branch
00125                                                                  const char *prefName,
00126                                                                  const nsString& defValue,
00127                                                                  nsXPIDLString& prefValue);
00128 
00133 NS_MSG_BASE nsresult GetOrCreateFolder(const nsACString & aURI, nsIUrlListener *aListener);
00134 
00135 // Returns true if the nsIURI is a message under an RSS account
00136 NS_MSG_BASE nsresult IsRSSArticle(nsIURI * aMsgURI, PRBool *aIsRSSArticle);
00137 
00138 // digest needs to be a pointer to a 16 byte buffer
00139 #define DIGEST_LENGTH 16
00140 
00141 NS_MSG_BASE nsresult MSGCramMD5(const char *text, PRInt32 text_len, const char *key, PRInt32 key_len, unsigned char *digest);
00142 NS_MSG_BASE nsresult MSGApopMD5(const char *text, PRInt32 text_len, const char *password, PRInt32 password_len, unsigned char *digest);
00143 
00144 // helper functions to convert a 64bits PRTime into a 32bits value (compatible time_t) and vice versa.
00145 NS_MSG_BASE void PRTime2Seconds(PRTime prTime, PRUint32 *seconds);
00146 NS_MSG_BASE void PRTime2Seconds(PRTime prTime, PRInt32 *seconds);
00147 NS_MSG_BASE void Seconds2PRTime(PRUint32 seconds, PRTime *prTime);
00148 // helper function to generate current date+time as a string
00149 NS_MSG_BASE void MsgGenerateNowStr(nsACString &nowStr);
00150 
00151 // fills in the position of the passed in keyword in the passed in keyword list
00152 // and returns false if the keyword isn't present
00153 NS_MSG_BASE PRBool MsgFindKeyword(const nsACString &keyword, nsACString &keywords, 
00154                                   nsACString::const_iterator &start, 
00155                                   nsACString::const_iterator &end);
00156 
00157 NS_MSG_BASE PRBool MsgHostDomainIsTrusted(nsCString &host, nsCString &trustedMailDomains);
00158 
00159 NS_MSG_BASE nsresult MsgMailboxGetURI(const char *nativepath, nsCString &mailboxUri);
00160 
00161 NS_MSG_BASE void MsgStripQuotedPrintable (unsigned char *src);
00162 
00163 #endif
00164