kmime_util.h
00001 /* -*- c++ -*- 00002 kmime_util.h 00003 00004 KMime, the KDE internet mail/usenet news message library. 00005 Copyright (c) 2001 the KMime authors. 00006 See file AUTHORS for details 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 You should have received a copy of the GNU General Public License 00013 along with this program; if not, write to the Free Software Foundation, 00014 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US 00015 */ 00016 #ifndef __KMIME_UTIL_H__ 00017 #define __KMIME_UTIL_H__ 00018 00019 #include "tqdatetime.h" 00020 #include "tqstring.h" 00021 #include "tqcstring.h" 00022 #include "tqvaluelist.h" 00023 #include "time.h" 00024 #include <tdepimmacros.h> 00025 00026 typedef TQValueList<TQCString> QCStringList; 00027 00028 namespace KMime { 00029 00032 extern const char* cachedCharset(const TQCString &name) KDE_EXPORT; 00033 00036 extern const char* cachedLanguage(const TQCString &name) KDE_EXPORT; 00037 00039 extern bool isUsAscii(const TQString &s) KDE_EXPORT; 00040 00041 inline bool isOfSet(const uchar map[16], unsigned char ch) { 00042 Q_ASSERT( ch < 128 ); 00043 return ( map[ ch/8 ] & 0x80 >> ch%8 ); 00044 } 00045 00046 extern const uchar specialsMap[16]; 00047 extern const uchar tSpecialsMap[16]; 00048 extern const uchar aTextMap[16]; 00049 extern const uchar tTextMap[16]; 00050 extern const uchar eTextMap[16]; 00051 00052 inline bool isSpecial(char ch) { 00053 return isOfSet( specialsMap, ch ); 00054 } 00055 inline bool isTSpecial(char ch) { 00056 return isOfSet( tSpecialsMap, ch ); 00057 } 00058 inline bool isAText(char ch) { 00059 return isOfSet( aTextMap, ch ); 00060 } 00061 inline bool isTText(char ch) { 00062 return isOfSet( tTextMap, ch ); 00063 } 00064 inline bool isEText(char ch) { 00065 return isOfSet( eTextMap, ch ); 00066 } 00067 00077 extern TQString decodeRFC2047String(const TQCString &src, const char **usedCS, 00078 const TQCString &defaultCS, bool forceCS) KDE_EXPORT; 00079 00085 extern TQString decodeRFC2047String(const TQCString &src) KDE_EXPORT; 00086 00097 extern TQCString encodeRFC2047String(const TQString &src, const char *charset, 00098 bool addressHeader=false, bool allow8bitHeaders=false) KDE_EXPORT; 00099 00106 extern TQCString uniqueString() KDE_EXPORT; 00107 00114 extern TQCString multiPartBoundary() KDE_EXPORT; 00115 00123 extern TQCString extractHeader(const TQCString &src, const char *name) KDE_EXPORT; 00133 extern TQCString CRLFtoLF(const TQCString &s) KDE_EXPORT; 00143 extern TQCString CRLFtoLF(const char *s) KDE_EXPORT; 00155 extern TQCString LFtoCRLF(const TQCString &s) KDE_EXPORT; 00156 00162 KDE_EXPORT extern void removeQuots(TQCString &str); 00168 KDE_EXPORT extern void removeQuots(TQString &str); 00175 KDE_EXPORT extern void addQuotes(TQCString &str, bool forceQuotes); 00176 00177 00194 class KDE_EXPORT DateFormatter { 00195 public: 00196 enum FormatType { 00197 CTime, //< ctime "Sun Mar 31 02:08:35 2002" 00198 Localized, //< localized "2002-03-31 02:08" 00199 Fancy, //< fancy "Today 02:08:35" 00200 Iso, //< iso "2002-03-31 02:08:35" 00201 Custom //< custom "whatever you like" 00202 }; 00203 00208 DateFormatter(FormatType fType = DateFormatter::Fancy); 00209 00210 ~DateFormatter(); 00211 00215 FormatType getFormat() const; 00219 void setFormat(FormatType t); 00220 00229 TQString dateString(time_t otime, const TQString& lang = TQString(), 00230 bool shortFormat = true, bool includeSecs=false) const; 00234 TQString dateString(const TQDateTime& dtime, const TQString& lang = TQString(), 00235 bool shortFormat = true, bool includeSecs=false) const; 00236 00237 00247 void setCustomFormat(const TQString& format); 00248 TQString getCustomFormat() const; 00249 00254 TQCString rfc2822(time_t otime) const; 00258 void reset(); 00259 00260 //statics 00269 static TQString formatDate( DateFormatter::FormatType t, time_t time, 00270 const TQString& data = TQString(), 00271 bool shortFormat = true, bool includeSecs=false); 00272 00281 static TQString formatCurrentDate( DateFormatter::FormatType t, 00282 const TQString& data = TQString(), 00283 bool shortFormat = true, bool includeSecs=false); 00284 00286 static TQCString rfc2822FormatDate( time_t time ); 00287 static bool isDaylight(); 00288 protected: 00294 TQString fancy(time_t otime) const ; 00303 TQString localized(time_t otime, bool shortFormat = true, bool includeSecs = false, 00304 const TQString& localeLanguage=TQString() ) const; 00309 TQString cTime(time_t otime) const; 00314 TQString isoDate(time_t otime) const; 00315 00322 TQString custom(time_t t) const; 00327 TQCString zone(time_t otime) const; 00328 00329 time_t qdateToTimeT(const TQDateTime& dt) const; 00330 private: 00331 FormatType mFormat; 00332 mutable time_t mCurrentTime; 00333 mutable TQDateTime mDate; 00334 TQString mCustomFormat; 00335 static int mDaylight; 00336 }; 00337 00338 } // namespace KMime 00339 00340 #endif /* __KMIME_UTIL_H__ */