libkmime

kmime_content.h
1 /*
2  kmime_content.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_CONTENT_H__
17 #define __KMIME_CONTENT_H__
18 
19 //forward declarations
20 #if 0
23 class KMime::Headers::ContentType;
24 class KMime::Headers::CTEncoding;
25 class KMime::Headers::CDisposition;
26 class KMime::Headers::List;
27 #endif
28 
29 #include "kmime_util.h"
30 #include "kmime_headers.h"
31 
32 #include <tqtextstream.h>
33 
34 namespace KMime {
35 
36 
42 class Base {
43 
44  public:
45 
46  //enums
47  enum articleType { ATmimeContent,
48  ATremote,
49  ATlocal };
50 
51 };
52 
53 
59 class TDE_EXPORT Content : public Base {
60 
61  public:
62  typedef TQPtrList<KMime::Content> List;
63 
64  Content();
65  Content(const TQCString &h, const TQCString &b);
66  virtual ~Content();
67 
68  //type
69  virtual articleType type() { return ATmimeContent; }
70 
71  //content handling
72  bool hasContent() { return ( !h_ead.isEmpty() && (!b_ody.isEmpty() || (c_ontents && !c_ontents->isEmpty())) ); }
73  void setContent(TQStrList *l);
74  void setContent(const TQCString &s);
75  virtual void parse();
76  virtual void assemble();
77  virtual void clear();
78 
79  //header access
80  TQCString head() { return h_ead; }
81  // extracts and removes the next header from head. The caller has to delete the returned header;
82  Headers::Generic* getNextHeader(TQCString &head);
83  virtual Headers::Base* getHeaderByType(const char *type);
84  virtual void setHeader(Headers::Base *h);
85  virtual bool removeHeader(const char *type);
86  bool hasHeader(const char *type) { return (getHeaderByType(type)!=0); }
87  Headers::ContentType* contentType(bool create=true) { Headers::ContentType *p=0; return getHeaderInstance(p, create); }
88  Headers::CTEncoding* contentTransferEncoding(bool create=true) { Headers::CTEncoding *p=0; return getHeaderInstance(p, create); }
89  Headers::CDisposition* contentDisposition(bool create=true) { Headers::CDisposition *p=0; return getHeaderInstance(p, create); }
90  Headers::CDescription* contentDescription(bool create=true) { Headers::CDescription *p=0; return getHeaderInstance(p, create); }
91 
92  //content access
93  int size();
94  int storageSize();
95  int lineCount();
96  TQCString body() { return b_ody; }
97  void setBody( const TQCString & str ) { b_ody = str; }
98  TQCString encodedContent(bool useCrLf=false);
99  TQByteArray decodedContent();
100  void decodedText(TQString &s, bool trimText=false,
101  bool removeTrailingNewlines=false);
102  void decodedText(TQStringList &s, bool trimText=false,
103  bool removeTrailingNewlines=false);
104  void fromUnicodeString(const TQString &s);
105 
106  Content* textContent();
107  void attachments(List *dst, bool incAlternatives=false);
108  void addContent(Content *c, bool prepend=false);
109  void removeContent(Content *c, bool del=false);
110  void changeEncoding(Headers::contentEncoding e);
111 
112  //saves the encoded content to the given textstream
113  // scrambleFromLines: replace "\nFrom " with "\n>From ", this is
114  // needed to avoid problem with mbox-files
115  void toStream(TQTextStream &ts, bool scrambleFromLines=false);
116 
117  // this charset is used for all headers and the body
118  // if the charset is not declared explictly
119  TQCString defaultCharset() { return TQCString(d_efaultCS); }
120  void setDefaultCharset(const TQCString &cs);
121 
122  // use the default charset even if a different charset is
123  // declared in the article
124  bool forceDefaultCS() { return f_orceDefaultCS; }
125 
126  // enables/disables the force mode, housekeeping.
127  // works correctly only when the article is completely empty or
128  // completely loaded
129  virtual void setForceDefaultCS(bool b);
130 
131 
132  protected:
133  TQCString rawHeader(const char *name);
134  bool decodeText();
135  template <class T> T* getHeaderInstance(T *ptr, bool create);
136 
137  TQCString h_ead,
138  b_ody;
139  List *c_ontents;
140  Headers::Base::List *h_eaders;
141  const char *d_efaultCS;
142  bool f_orceDefaultCS;
143 
144 };
145 
146 // some compilers (for instance Compaq C++) need template inline functions
147 // here rather than in the *.cpp file
148 
149 template <class T> T* Content::getHeaderInstance(T *ptr, bool create)
150 {
151  T dummy; //needed to access virtual member T::type()
152 
153  ptr=static_cast <T*> (getHeaderByType(dummy.type()));
154  if(!ptr && create) { //no such header found, but we need one => create it
155  ptr=new T(this);
156  if(!(h_eaders)) {
157  h_eaders=new Headers::Base::List();
158  h_eaders->setAutoDelete(true);
159  }
160  h_eaders->append(ptr);
161  }
162 
163  return ptr;
164 }
165 
166 
167 
168 } // namespace KMime
169 
170 #endif // __KMIME_CONTENT_H__
Base class for messages in mime format It contains all the enums, static functions and parser-classes...
Definition: kmime_content.h:42
This class encapsulates a mime-encoded content.
Definition: kmime_content.h:59
Baseclass of all header-classes.
Represents an arbitrary header, that can contain any header-field.