kmail

templateparser.h
00001 /*   -*- mode: C++; c-file-style: "gnu" -*-
00002  *   kmail: KDE mail client
00003  *   This file: Copyright (C) 2006 Dmitry Morozhnikov <dmiceman@mail.ru>
00004  *
00005  *   This program is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   This program is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with this program; if not, write to the Free Software
00017  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  */
00020 
00021 #ifndef __KMAIL_TEMPLATEPARSER_H__
00022 #define __KMAIL_TEMPLATEPARSER_H__
00023 
00024 #include <tqobject.h>
00025 
00026 class KMMessage;
00027 class TQString;
00028 class KMFolder;
00029 class TQObject;
00030 class TDEProcess;
00031 
00054 class TemplateParser : public TQObject
00055 {
00056   Q_OBJECT
00057   
00058 
00059   public:
00060     enum Mode {
00061       NewMessage,
00062       Reply,
00063       ReplyAll,
00064       Forward
00065     };
00066 
00067     static const int PipeTimeout = 15;
00068 
00069   public:
00070     TemplateParser( KMMessage *amsg, const Mode amode );
00071     ~TemplateParser();
00072 
00079     void setSelection( const TQString &selection );
00080 
00089     void setAllowDecryption( const bool allowDecryption );
00090 
00091     virtual void process( KMMessage *aorig_msg, KMFolder *afolder = 0, bool append = false );
00092     virtual void process( const TQString &tmplName, KMMessage *aorig_msg,
00093                           KMFolder *afolder = 0, bool append = false );
00094     virtual void processWithTemplate( const TQString &tmpl );
00095 
00100     virtual TQString findTemplate();
00101 
00105     virtual TQString findCustomTemplate( const TQString &tmpl );
00106 
00107     virtual TQString pipe( const TQString &cmd, const TQString &buf );
00108 
00109     virtual TQString getFName( const TQString &str );
00110     virtual TQString getLName( const TQString &str );
00111 
00112   protected:
00113     Mode mMode;
00114     KMFolder *mFolder;
00115     uint mIdentity;
00116     KMMessage *mMsg;
00117     KMMessage *mOrigMsg;
00118     TQString mSelection;
00119     bool mAllowDecryption;
00120     int mPipeRc;
00121     TQString mPipeOut;
00122     TQString mPipeErr;
00123     bool mDebug;
00124     TQString mQuoteString;
00125     bool mAppend;
00126     TQString mTo, mCC;
00127     partNode *mOrigRoot;
00128 
00136     TQString messageText( bool allowSelectionOnly );
00137 
00143     partNode* parsedObjectTree();
00144 
00154     void addProcessedBodyToMessage( const TQString &body );
00155 
00160     bool shouldStripSignature() const;
00161 
00162     int parseQuotes( const TQString &prefix, const TQString &str,
00163                      TQString &quote ) const;
00164 
00165   protected slots:
00166     void onProcessExited( TDEProcess *proc );
00167     void onReceivedStdout( TDEProcess *proc, char *buffer, int buflen );
00168     void onReceivedStderr( TDEProcess *proc, char *buffer, int buflen );
00169     void onWroteStdin( TDEProcess *proc );
00170 };
00171 
00172 #endif // __KMAIL_TEMPLATEPARSER_H__