00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __KIOSMTP_TRANSACTIONSTATE_H__
00033 #define __KIOSMTP_TRANSACTIONSTATE_H__
00034
00035 #include "response.h"
00036
00037 #include <tqstring.h>
00038 #include <tqvaluelist.h>
00039
00040 namespace KioSMTP {
00041
00063 class TransactionState {
00064 public:
00065 struct RecipientRejection {
00066 RecipientRejection( const TQString & who=TQString::null,
00067 const TQString & why=TQString::null )
00068 : recipient( who ), reason( why ) {}
00069 TQString recipient;
00070 TQString reason;
00071 #ifdef KIOSMTP_COMPARATORS
00072 bool operator==( const RecipientRejection & other ) const {
00073 return recipient == other.recipient && reason == other.reason;
00074 }
00075 #endif
00076 };
00077 typedef TQValueList<RecipientRejection> RejectedRecipientList;
00078
00079 TransactionState( bool rcptToDenyIsFailure=true )
00080 : mErrorCode( 0 ),
00081 mRcptToDenyIsFailure( rcptToDenyIsFailure ),
00082 mAtLeastOneRecipientWasAccepted( false ),
00083 mDataCommandIssued( false ),
00084 mDataCommandSucceeded( false ),
00085 mFailed( false ),
00086 mFailedFatally( false ),
00087 mComplete( false ) {}
00088
00092 bool failed() const { return mFailed || mFailedFatally; }
00093 void setFailed() { mFailed = true; }
00094
00098 bool failedFatally() const { return mFailedFatally; }
00099 void setFailedFatally( int code=0, const TQString & msg=TQString::null );
00100
00102 bool complete() const { return mComplete; }
00103 void setComplete() { mComplete = true; }
00104
00107 int errorCode() const;
00110 TQString errorMessage() const;
00111
00112 void setMailFromFailed( const TQString & addr, const Response & r );
00113
00114 bool dataCommandIssued() const { return mDataCommandIssued; }
00115 void setDataCommandIssued( bool issued ) { mDataCommandIssued = issued; }
00116
00117 bool dataCommandSucceeded() const {
00118 return mDataCommandIssued && mDataCommandSucceeded;
00119 }
00120 void setDataCommandSucceeded( bool succeeded, const Response & r );
00121
00122 Response dataResponse() const {
00123 return mDataResponse;
00124 }
00125
00126 bool atLeastOneRecipientWasAccepted() const {
00127 return mAtLeastOneRecipientWasAccepted;
00128 }
00129 void setRecipientAccepted() {
00130 mAtLeastOneRecipientWasAccepted = true;
00131 }
00132
00133 bool haveRejectedRecipients() const {
00134 return !mRejectedRecipients.empty();
00135 }
00136 RejectedRecipientList rejectedRecipients() const {
00137 return mRejectedRecipients;
00138 }
00139 void addRejectedRecipient( const RecipientRejection & r );
00140 void addRejectedRecipient( const TQString & who, const TQString & why ) {
00141 addRejectedRecipient( RecipientRejection( who, why ) );
00142 }
00143
00144 void clear() {
00145 mRejectedRecipients.clear();
00146 mDataResponse.clear();
00147 mAtLeastOneRecipientWasAccepted
00148 = mDataCommandIssued
00149 = mDataCommandSucceeded
00150 = mFailed = mFailedFatally
00151 = mComplete = false;
00152 }
00153
00154 #ifdef KIOSMTP_COMPARATORS
00155 bool operator==( const TransactionState & other ) const {
00156 return
00157 mAtLeastOneRecipientWasAccepted == other.mAtLeastOneRecipientWasAccepted &&
00158 mDataCommandIssued == other.mDataCommandIssued &&
00159 mDataCommandSucceeded == other.mDataCommandSucceeded &&
00160 mFailed == other.mFailed &&
00161 mFailedFatally == other.mFailedFatally &&
00162 mComplete == other.mComplete &&
00163 mDataResponse.code() == other.mDataResponse.code() &&
00164 mRejectedRecipients == other.mRejectedRecipients;
00165 }
00166 #endif
00167
00168
00169 private:
00170 RejectedRecipientList mRejectedRecipients;
00171 Response mDataResponse;
00172 TQString mErrorMessage;
00173 int mErrorCode;
00174 bool mRcptToDenyIsFailure;
00175 bool mAtLeastOneRecipientWasAccepted;
00176 bool mDataCommandIssued;
00177 bool mDataCommandSucceeded;
00178 bool mFailed;
00179 bool mFailedFatally;
00180 bool mComplete;
00181 };
00182
00183 }
00184
00185 #endif // __KIOSMTP_TRANSACTIONSTATE_H__