6 #include "mailinglist-magic.h" 10 #include <tdeconfig.h> 14 #include <tqstringlist.h> 16 using namespace KMail;
18 typedef TQString (*MagicDetectorFunc) (
const KMMessage *, TQCString &, TQString &);
21 static TQString check_sender(
const KMMessage *message,
22 TQCString &header_name,
23 TQString &header_value )
27 if ( header.isEmpty() )
30 if ( header.left( 6 ) ==
"owner-" )
32 header_name =
"Sender";
33 header_value = header;
34 header = header.mid( 6, header.find(
'@' ) - 6 );
37 int index = header.find(
"-owner@ " );
41 header.truncate( index );
42 header_name =
"Sender";
43 header_value = header;
50 static TQString check_x_beenthere(
const KMMessage *message,
51 TQCString &header_name,
52 TQString &header_value )
54 TQString header = message->
headerField(
"X-BeenThere" );
55 if ( header.isNull() || header.find(
'@' ) == -1 )
58 header_name =
"X-BeenThere";
59 header_value = header;
60 header.truncate( header.find(
'@' ) );
65 static TQString check_delivered_to(
const KMMessage *message,
66 TQCString &header_name,
67 TQString &header_value )
69 TQString header = message->
headerField(
"Delivered-To" );
70 if ( header.isNull() || header.left(13 ) !=
"mailing list" 71 || header.find(
'@' ) == -1 )
74 header_name =
"Delivered-To";
75 header_value = header;
77 return header.mid( 13, header.find(
'@' ) - 13 );
81 static TQString check_x_mailing_list(
const KMMessage *message,
82 TQCString &header_name,
83 TQString &header_value )
85 TQString header = message->
headerField(
"X-Mailing-List");
86 if ( header.isEmpty() )
89 if ( header.find(
'@' ) < 1 )
92 header_name =
"X-Mailing-List";
93 header_value = header;
94 if ( header[0] ==
'<' )
95 header = header.mid(1, header.find(
'@' ) - 1);
97 header.truncate( header.find(
'@' ) );
102 static TQString check_list_id(
const KMMessage *message,
103 TQCString &header_name,
104 TQString &header_value )
106 int lAnglePos, firstDotPos;
107 TQString header = message->
headerField(
"List-Id" );
108 if ( header.isEmpty() )
111 lAnglePos = header.find(
'<' );
115 firstDotPos = header.find(
'.', lAnglePos );
116 if ( firstDotPos < 0 )
119 header_name =
"List-Id";
120 header_value = header.mid( lAnglePos );
121 header = header.mid( lAnglePos + 1, firstDotPos - lAnglePos - 1 );
127 static TQString check_list_post(
const KMMessage *message,
128 TQCString &header_name,
129 TQString &header_value )
131 TQString header = message->
headerField(
"List-Post" );
132 if ( header.isEmpty() )
135 int lAnglePos = header.find(
"<mailto:" );
139 header_name =
"List-Post";
140 header_value = header;
141 header = header.mid( lAnglePos + 8, header.length());
142 header.truncate( header.find(
'@') );
147 static TQString check_mailing_list(
const KMMessage *message,
148 TQCString &header_name,
149 TQString &header_value )
151 TQString header = message->
headerField(
"Mailing-List");
152 if ( header.isEmpty() )
155 if (header.left( 5 ) !=
"list " || header.find(
'@' ) < 5 )
158 header_name =
"Mailing-List";
159 header_value = header;
160 header = header.mid(5, header.find(
'@' ) - 5);
166 static TQString check_x_loop(
const KMMessage *message,
167 TQCString &header_name,
168 TQString &header_value ){
170 if ( header.isEmpty() )
173 if (header.find(
'@' ) < 2 )
176 header_name =
"X-Loop";
177 header_value = header;
178 header.truncate(header.find(
'@' ));
183 static TQString check_x_ml_name(
const KMMessage *message,
184 TQCString &header_name,
185 TQString &header_value ){
186 TQString header = message->
headerField(
"X-ML-Name");
187 if ( header.isEmpty() )
190 header_name =
"X-ML-Name";
191 header_value = header;
192 header.truncate(header.find(
'@' ));
196 MagicDetectorFunc magic_detector[] =
201 check_x_mailing_list,
209 static const int num_detectors =
sizeof (magic_detector) /
sizeof (magic_detector[0]);
212 headerToAddress(
const TQString& header )
218 if ( header.isEmpty() )
221 while ( (start = header.find(
"<", start )) != -1 ) {
222 if ( (end = header.find(
">", ++start ) ) == -1 ) {
223 kdDebug(5006)<<k_funcinfo<<
"Serious mailing list header parsing error !"<<endl;
226 kdDebug(5006)<<
"Mailing list = "<<header.mid( start, end - start )<<endl;
227 addr.append( header.mid( start, end - start ) );
233 MailingList::detect(
const KMMessage *message )
237 mlist.setPostURLS( headerToAddress(
239 mlist.setHelpURLS( headerToAddress(
241 mlist.setSubscribeURLS( headerToAddress(
243 mlist.setUnsubscribeURLS( headerToAddress(
245 mlist.setArchiveURLS( headerToAddress(
253 MailingList::name(
const KMMessage *message, TQCString &header_name,
254 TQString &header_value )
257 header_name = TQCString();
258 header_value = TQString();
263 for (
int i = 0; i < num_detectors; i++) {
264 mlist = magic_detector[i] (message, header_name, header_value);
265 if ( !mlist.isNull() )
272 MailingList::MailingList()
273 : mFeatures( None ), mHandler(
KMail )
278 MailingList::features()
const 284 MailingList::setHandler( MailingList::Handler han )
289 MailingList::handler()
const 295 MailingList::setPostURLS (
const KURL::List& lst )
304 MailingList::postURLS()
const 310 MailingList::setSubscribeURLS(
const KURL::List& lst )
312 mFeatures |= Subscribe;
314 mFeatures ^= Subscribe;
317 mSubscribeURLS = lst;
320 MailingList::subscribeURLS()
const 322 return mSubscribeURLS;
326 MailingList::setUnsubscribeURLS(
const KURL::List& lst )
328 mFeatures |= Unsubscribe;
330 mFeatures ^= Unsubscribe;
333 mUnsubscribeURLS = lst;
335 KURL::List MailingList::unsubscribeURLS()
const 337 return mUnsubscribeURLS;
341 MailingList::setHelpURLS(
const KURL::List& lst )
351 MailingList::helpURLS()
const 357 MailingList::setArchiveURLS(
const KURL::List& lst )
359 mFeatures |= Archive;
361 mFeatures ^= Archive;
367 MailingList::archiveURLS()
const 373 MailingList::setId(
const TQString& str )
376 if ( str.isEmpty() ) {
383 MailingList::id()
const 389 MailingList::writeConfig( TDEConfig* config )
const 391 config->writeEntry(
"MailingListFeatures", mFeatures );
392 config->writeEntry(
"MailingListHandler", mHandler );
393 config->writeEntry(
"MailingListId", mId );
394 config->writeEntry(
"MailingListPostingAddress", mPostURLS.toStringList() );
395 config->writeEntry(
"MailingListSubscribeAddress", mSubscribeURLS.toStringList() );
396 config->writeEntry(
"MailingListUnsubscribeAddress", mUnsubscribeURLS.toStringList() );
397 config->writeEntry(
"MailingListArchiveAddress", mArchiveURLS.toStringList() );
398 config->writeEntry(
"MailingListHelpAddress", mHelpURLS.toStringList() );
402 MailingList::readConfig( TDEConfig* config )
404 mFeatures = config->readNumEntry(
"MailingListFeatures", 0 );
405 mHandler =
static_cast<MailingList::Handler
>(
406 config->readNumEntry(
"MailingListHandler", MailingList::KMail ) );
408 mId = config->readEntry(
"MailingListId");
409 mPostURLS = config->readListEntry(
"MailingListPostingAddress" );
410 mSubscribeURLS = config->readListEntry(
"MailingListSubscribeAddress" );
411 mUnsubscribeURLS = config->readListEntry(
"MailingListUnsubscribeAddress" );
412 mArchiveURLS = config->readListEntry(
"MailingListArchiveAddress" );
413 mHelpURLS = config->readListEntry(
"MailingListHelpAddress" );
Class is used for all Mailing List handling inside KMail.
TQString headerField(const TQCString &name) const
Returns the value of a header field with the given name.