libkmime

kmime_newsarticle.cpp
1 /*
2  kmime_newsarticle.cpp
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 #include "kmime_newsarticle.h"
17 
18 using namespace KMime;
19 
20 namespace KMime {
21 
22 void NewsArticle::parse()
23 {
24  Message::parse();
25 
26  TQCString raw;
27 
28  if( !(raw=rawHeader(l_ines.type())).isEmpty() )
29  l_ines.from7BitString(raw);
30 }
31 
32 void NewsArticle::assemble()
33 {
34  Headers::Base *h;
35  TQCString newHead="";
36 
37  //Message-ID
38  if( (h=messageID(false))!=0 )
39  newHead+=h->as7BitString()+"\n";
40 
41  //Control
42  if( (h=control(false))!=0 )
43  newHead+=h->as7BitString()+"\n";
44 
45  //Supersedes
46  if( (h=supersedes(false))!=0 )
47  newHead+=h->as7BitString()+"\n";
48 
49  //From
50  h=from(); // "From" is mandatory
51  newHead+=h->as7BitString()+"\n";
52 
53  //Subject
54  h=subject(); // "Subject" is mandatory
55  newHead+=h->as7BitString()+"\n";
56 
57  //To
58  if( (h=to(false))!=0 )
59  newHead+=h->as7BitString()+"\n";
60 
61  //Newsgroups
62  if( (h=newsgroups(false))!=0 )
63  newHead+=h->as7BitString()+"\n";
64 
65  //Followup-To
66  if( (h=followUpTo(false))!=0 )
67  newHead+=h->as7BitString()+"\n";
68 
69  //Reply-To
70  if( (h=replyTo(false))!=0 )
71  newHead+=h->as7BitString()+"\n";
72 
73  //Mail-Copies-To
74  if( (h=mailCopiesTo(false))!=0 )
75  newHead+=h->as7BitString()+"\n";
76 
77  //Date
78  h=date(); // "Date" is mandatory
79  newHead+=h->as7BitString()+"\n";
80 
81  //References
82  if( (h=references(false))!=0 )
83  newHead+=h->as7BitString()+"\n";
84 
85  //Lines
86  h=lines(); // "Lines" is mandatory
87  newHead+=h->as7BitString()+"\n";
88 
89  //Organization
90  if( (h=organization(false))!=0 )
91  newHead+=h->as7BitString()+"\n";
92 
93  //User-Agent
94  if( (h=userAgent(false))!=0 )
95  newHead+=h->as7BitString()+"\n";
96 
97  //Mime-Version
98  newHead+="MIME-Version: 1.0\n";
99 
100  //Content-Type
101  newHead+=contentType()->as7BitString()+"\n";
102 
103  //Content-Transfer-Encoding
104  newHead+=contentTransferEncoding()->as7BitString()+"\n";
105 
106  //X-Headers
107  int pos=h_ead.find("\nX-");
108  if(pos>-1) //we already have some x-headers => "recycle" them
109  newHead+=h_ead.mid(pos+1, h_ead.length()-pos);
110  else if(h_eaders && !h_eaders->isEmpty()) {
111  for(h=h_eaders->first(); h; h=h_eaders->next()) {
112  if( h->isXHeader() && (strncasecmp(h->type(), "X-KNode", 7)!=0) )
113  newHead+=h->as7BitString()+"\n";
114  }
115  }
116 
117  h_ead=newHead;
118 }
119 
120 void NewsArticle::clear()
121 {
122  l_ines.clear();
123  Message::clear();
124 }
125 
126 Headers::Base * NewsArticle::getHeaderByType(const char * type)
127 {
128  if(strcasecmp("Lines", type)==0) {
129  if(l_ines.isEmpty()) return 0;
130  else return &l_ines;
131  } else
132  return Message::getHeaderByType(type);
133 }
134 
135 void NewsArticle::setHeader(Headers::Base *h)
136 {
137  bool del=true;
138  if(h->is("Lines"))
139  l_ines.setNumberOfLines( (static_cast<Headers::Lines*>(h))->numberOfLines() );
140  else {
141  del=false;
142  Message::setHeader(h);
143  }
144 
145  if(del) delete h;
146 }
147 
148 
149 bool NewsArticle::removeHeader(const char *type)
150 {
151  if(strcasecmp("Lines", type)==0)
152  l_ines.clear();
153  else
154  return Message::removeHeader(type);
155 
156  return true;
157 }
158 
159 
160 } // namespace KMime
Baseclass of all header-classes.
bool isXHeader()
Check if this header is a X-Header.
virtual const char * type()
Return the type of this header (e.g.
virtual TQCString as7BitString(bool=true)
Return the encoded header.
virtual void clear()
Delete.
bool is(const char *t)
Check if this header is of type t.
Represents a "Lines" header.