libkmime
kmime_newsarticle.cpp
00001 /* 00002 kmime_newsarticle.cpp 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 #include "kmime_newsarticle.h" 00017 00018 using namespace KMime; 00019 00020 namespace KMime { 00021 00022 void NewsArticle::parse() 00023 { 00024 Message::parse(); 00025 00026 QCString raw; 00027 00028 if( !(raw=rawHeader(l_ines.type())).isEmpty() ) 00029 l_ines.from7BitString(raw); 00030 } 00031 00032 void NewsArticle::assemble() 00033 { 00034 Headers::Base *h; 00035 QCString newHead=""; 00036 00037 //Message-ID 00038 if( (h=messageID(false))!=0 ) 00039 newHead+=h->as7BitString()+"\n"; 00040 00041 //Control 00042 if( (h=control(false))!=0 ) 00043 newHead+=h->as7BitString()+"\n"; 00044 00045 //Supersedes 00046 if( (h=supersedes(false))!=0 ) 00047 newHead+=h->as7BitString()+"\n"; 00048 00049 //From 00050 h=from(); // "From" is mandatory 00051 newHead+=h->as7BitString()+"\n"; 00052 00053 //Subject 00054 h=subject(); // "Subject" is mandatory 00055 newHead+=h->as7BitString()+"\n"; 00056 00057 //To 00058 if( (h=to(false))!=0 ) 00059 newHead+=h->as7BitString()+"\n"; 00060 00061 //Newsgroups 00062 if( (h=newsgroups(false))!=0 ) 00063 newHead+=h->as7BitString()+"\n"; 00064 00065 //Followup-To 00066 if( (h=followUpTo(false))!=0 ) 00067 newHead+=h->as7BitString()+"\n"; 00068 00069 //Reply-To 00070 if( (h=replyTo(false))!=0 ) 00071 newHead+=h->as7BitString()+"\n"; 00072 00073 //Mail-Copies-To 00074 if( (h=mailCopiesTo(false))!=0 ) 00075 newHead+=h->as7BitString()+"\n"; 00076 00077 //Date 00078 h=date(); // "Date" is mandatory 00079 newHead+=h->as7BitString()+"\n"; 00080 00081 //References 00082 if( (h=references(false))!=0 ) 00083 newHead+=h->as7BitString()+"\n"; 00084 00085 //Lines 00086 h=lines(); // "Lines" is mandatory 00087 newHead+=h->as7BitString()+"\n"; 00088 00089 //Organization 00090 if( (h=organization(false))!=0 ) 00091 newHead+=h->as7BitString()+"\n"; 00092 00093 //User-Agent 00094 if( (h=userAgent(false))!=0 ) 00095 newHead+=h->as7BitString()+"\n"; 00096 00097 //Mime-Version 00098 newHead+="MIME-Version: 1.0\n"; 00099 00100 //Content-Type 00101 newHead+=contentType()->as7BitString()+"\n"; 00102 00103 //Content-Transfer-Encoding 00104 newHead+=contentTransferEncoding()->as7BitString()+"\n"; 00105 00106 //X-Headers 00107 int pos=h_ead.find("\nX-"); 00108 if(pos>-1) //we already have some x-headers => "recycle" them 00109 newHead+=h_ead.mid(pos+1, h_ead.length()-pos); 00110 else if(h_eaders && !h_eaders->isEmpty()) { 00111 for(h=h_eaders->first(); h; h=h_eaders->next()) { 00112 if( h->isXHeader() && (strncasecmp(h->type(), "X-KNode", 7)!=0) ) 00113 newHead+=h->as7BitString()+"\n"; 00114 } 00115 } 00116 00117 h_ead=newHead; 00118 } 00119 00120 void NewsArticle::clear() 00121 { 00122 l_ines.clear(); 00123 Message::clear(); 00124 } 00125 00126 Headers::Base * NewsArticle::getHeaderByType(const char * type) 00127 { 00128 if(strcasecmp("Lines", type)==0) { 00129 if(l_ines.isEmpty()) return 0; 00130 else return &l_ines; 00131 } else 00132 return Message::getHeaderByType(type); 00133 } 00134 00135 void NewsArticle::setHeader(Headers::Base *h) 00136 { 00137 bool del=true; 00138 if(h->is("Lines")) 00139 l_ines.setNumberOfLines( (static_cast<Headers::Lines*>(h))->numberOfLines() ); 00140 else { 00141 del=false; 00142 Message::setHeader(h); 00143 } 00144 00145 if(del) delete h; 00146 } 00147 00148 00149 bool NewsArticle::removeHeader(const char *type) 00150 { 00151 if(strcasecmp("Lines", type)==0) 00152 l_ines.clear(); 00153 else 00154 return Message::removeHeader(type); 00155 00156 return true; 00157 } 00158 00159 00160 } // namespace KMime