libkmime

kmime_util.h
1 /*
2  kmime_util.h
3 
4  KMime, the KDE internet mail/usenet news message library.
5  Copyright (c) 2001 the KMime authors.
6  See file AUTHORS for details
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
15 */
16 #ifndef __KMIME_UTIL_H__
17 #define __KMIME_UTIL_H__
18 
19 #include "tqdatetime.h"
20 #include "tqstring.h"
21 #include "tqcstring.h"
22 #include "tqvaluelist.h"
23 #include "time.h"
24 #include <tdemacros.h>
25 
26 typedef TQValueList<TQCString> QCStringList;
27 
28 namespace KMime {
29 
32  extern const char* cachedCharset(const TQCString &name) TDE_EXPORT;
33 
36  extern const char* cachedLanguage(const TQCString &name) TDE_EXPORT;
37 
39  extern bool isUsAscii(const TQString &s) TDE_EXPORT;
40 
41  inline bool isOfSet(const uchar map[16], unsigned char ch) {
42  Q_ASSERT( ch < 128 );
43  return ( map[ ch/8 ] & 0x80 >> ch%8 );
44  }
45 
46  extern const uchar specialsMap[16];
47  extern const uchar tSpecialsMap[16];
48  extern const uchar aTextMap[16];
49  extern const uchar tTextMap[16];
50  extern const uchar eTextMap[16];
51 
52  inline bool isSpecial(char ch) {
53  return isOfSet( specialsMap, ch );
54  }
55  inline bool isTSpecial(char ch) {
56  return isOfSet( tSpecialsMap, ch );
57  }
58  inline bool isAText(char ch) {
59  return isOfSet( aTextMap, ch );
60  }
61  inline bool isTText(char ch) {
62  return isOfSet( tTextMap, ch );
63  }
64  inline bool isEText(char ch) {
65  return isOfSet( eTextMap, ch );
66  }
67 
77  extern TQString decodeRFC2047String(const TQCString &src, const char **usedCS,
78  const TQCString &defaultCS, bool forceCS) TDE_EXPORT;
79 
85  extern TQString decodeRFC2047String(const TQCString &src) TDE_EXPORT;
86 
97  extern TQCString encodeRFC2047String(const TQString &src, const char *charset,
98  bool addressHeader=false, bool allow8bitHeaders=false) TDE_EXPORT;
99 
106  extern TQCString uniqueString() TDE_EXPORT;
107 
114  extern TQCString multiPartBoundary() TDE_EXPORT;
115 
123  extern TQCString extractHeader(const TQCString &src, const char *name) TDE_EXPORT;
133  extern TQCString CRLFtoLF(const TQCString &s) TDE_EXPORT;
143  extern TQCString CRLFtoLF(const char *s) TDE_EXPORT;
155  extern TQCString LFtoCRLF(const TQCString &s) TDE_EXPORT;
156 
162  TDE_EXPORT extern void removeQuots(TQCString &str);
168  TDE_EXPORT extern void removeQuots(TQString &str);
175  TDE_EXPORT extern void addQuotes(TQCString &str, bool forceQuotes);
176 
177 
194  class TDE_EXPORT DateFormatter {
195  public:
196  enum FormatType {
197  CTime, //< ctime "Sun Mar 31 02:08:35 2002"
198  Localized, //< localized "2002-03-31 02:08"
199  Fancy, //< fancy "Today 02:08:35"
200  Iso, //< iso "2002-03-31 02:08:35"
201  Custom //< custom "whatever you like"
202  };
203 
208  DateFormatter(FormatType fType = DateFormatter::Fancy);
209 
210  ~DateFormatter();
211 
215  FormatType getFormat() const;
219  void setFormat(FormatType t);
220 
229  TQString dateString(time_t otime, const TQString& lang = TQString(),
230  bool shortFormat = true, bool includeSecs=false) const;
234  TQString dateString(const TQDateTime& dtime, const TQString& lang = TQString(),
235  bool shortFormat = true, bool includeSecs=false) const;
236 
237 
247  void setCustomFormat(const TQString& format);
248  TQString getCustomFormat() const;
249 
254  TQCString rfc2822(time_t otime) const;
258  void reset();
259 
260  //statics
269  static TQString formatDate( DateFormatter::FormatType t, time_t time,
270  const TQString& data = TQString(),
271  bool shortFormat = true, bool includeSecs=false);
272 
281  static TQString formatCurrentDate( DateFormatter::FormatType t,
282  const TQString& data = TQString(),
283  bool shortFormat = true, bool includeSecs=false);
284 
286  static TQCString rfc2822FormatDate( time_t time );
287  static bool isDaylight();
288  protected:
294  TQString fancy(time_t otime) const ;
303  TQString localized(time_t otime, bool shortFormat = true, bool includeSecs = false,
304  const TQString& localeLanguage=TQString() ) const;
309  TQString cTime(time_t otime) const;
314  TQString isoDate(time_t otime) const;
315 
322  TQString custom(time_t t) const;
327  TQCString zone(time_t otime) const;
328 
329  time_t qdateToTimeT(const TQDateTime& dt) const;
330  private:
331  FormatType mFormat;
332  mutable time_t mCurrentTime;
333  mutable TQDateTime mDate;
334  TQString mCustomFormat;
335  static int mDaylight;
336  };
337 
338 } // namespace KMime
339 
340 #endif /* __KMIME_UTIL_H__ */
class abstracting date formatting
Definition: kmime_util.h:194