libkmime
kmime_util.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __KMIME_UTIL_H__
00017 #define __KMIME_UTIL_H__
00018
00019 #include "qdatetime.h"
00020 #include "qstring.h"
00021 #include "qcstring.h"
00022 #include "qvaluelist.h"
00023 #include "time.h"
00024 #include <kdepimmacros.h>
00025
00026 typedef QValueList<QCString> QCStringList;
00027
00028 namespace KMime {
00029
00032 extern const char* cachedCharset(const QCString &name) KDE_EXPORT;
00033
00036 extern const char* cachedLanguage(const QCString &name) KDE_EXPORT;
00037
00039 extern bool isUsAscii(const QString &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 QString decodeRFC2047String(const QCString &src, const char **usedCS,
00078 const QCString &defaultCS, bool forceCS) KDE_EXPORT;
00079
00085 extern QString decodeRFC2047String(const QCString &src) KDE_EXPORT;
00086
00097 extern QCString encodeRFC2047String(const QString &src, const char *charset,
00098 bool addressHeader=false, bool allow8bitHeaders=false) KDE_EXPORT;
00099
00106 extern QCString uniqueString() KDE_EXPORT;
00107
00114 extern QCString multiPartBoundary() KDE_EXPORT;
00115
00123 extern QCString extractHeader(const QCString &src, const char *name) KDE_EXPORT;
00133 extern QCString CRLFtoLF(const QCString &s) KDE_EXPORT;
00143 extern QCString CRLFtoLF(const char *s) KDE_EXPORT;
00155 extern QCString LFtoCRLF(const QCString &s) KDE_EXPORT;
00156
00162 KDE_EXPORT extern void removeQuots(QCString &str);
00168 KDE_EXPORT extern void removeQuots(QString &str);
00175 KDE_EXPORT extern void addQuotes(QCString &str, bool forceQuotes);
00176
00177
00194 class KDE_EXPORT DateFormatter {
00195 public:
00196 enum FormatType {
00197 CTime,
00198 Localized,
00199 Fancy,
00200 Iso,
00201 Custom
00202 };
00203
00208 DateFormatter(FormatType fType = DateFormatter::Fancy);
00209
00210 ~DateFormatter();
00211
00215 FormatType getFormat() const;
00219 void setFormat(FormatType t);
00220
00229 QString dateString(time_t otime, const QString& lang = QString::null,
00230 bool shortFormat = true, bool includeSecs=false) const;
00234 QString dateString(const QDateTime& dtime, const QString& lang = QString::null,
00235 bool shortFormat = true, bool includeSecs=false) const;
00236
00237
00247 void setCustomFormat(const QString& format);
00248 QString getCustomFormat() const;
00249
00254 QCString rfc2822(time_t otime) const;
00258 void reset();
00259
00260
00269 static QString formatDate( DateFormatter::FormatType t, time_t time,
00270 const QString& data = QString::null,
00271 bool shortFormat = true, bool includeSecs=false);
00272
00281 static QString formatCurrentDate( DateFormatter::FormatType t,
00282 const QString& data = QString::null,
00283 bool shortFormat = true, bool includeSecs=false);
00284
00286 static QCString rfc2822FormatDate( time_t time );
00287 static bool isDaylight();
00288 protected:
00294 QString fancy(time_t otime) const ;
00303 QString localized(time_t otime, bool shortFormat = true, bool includeSecs = false,
00304 const QString& localeLanguage=QString::null ) const;
00309 QString cTime(time_t otime) const;
00314 QString isoDate(time_t otime) const;
00315
00322 QString custom(time_t t) const;
00327 QCString zone(time_t otime) const;
00328
00329 time_t qdateToTimeT(const QDateTime& dt) const;
00330 private:
00331 FormatType mFormat;
00332 mutable time_t mCurrentTime;
00333 mutable QDateTime mDate;
00334 QString mCustomFormat;
00335 static int mDaylight;
00336 };
00337
00338 }
00339
00340 #endif
|