Main Page | Compound List | File List | Compound Members | File Members

HeaderInfo Class Reference

#include <HeaderInfo.h>

List of all members.

Public Member Functions

 HeaderInfo (const bool doTrace)
 ~HeaderInfo ()
const char * subject ()
void subject (const char *pBuf)
const char * to ()
void to (const char *pBuf)
const char * from ()
void from (const char *pBuf)
const char * fromNoColon ()
void fromNoColon (const char *pBuf)
const char * reason ()
void reason (const char *pBuf)
const char * date ()
void date (const char *pBuf)
const MailFilter::classification klass ()
void klass (MailFilter::classification k)

Private Member Functions

 HeaderInfo (const HeaderInfo &rhs)
FILE * openTraceFile ()
void init ()

Private Attributes

const bool mDoTrace
char mSubject [128]
char mTo [128]
char mFrom [128]
char mFromNoColon [128]
char mDate [128]
char mReason [128]
MailFilter::classification mKlass


Detailed Description

Package information from the email header (e.g., the subject, to and from strings) for use in generating debug and garbage trace information.

Definition at line 50 of file HeaderInfo.h.


Constructor & Destructor Documentation

HeaderInfo::~HeaderInfo  ) 
 

If an email was marked as garbage and discarded, write out a garbage_trace entry if the class variable mDoTrace is set.

Definition at line 121 of file HeaderInfo.C.

References mDoTrace, and openTraceFile().

00122 {
00123   if (mDoTrace && klass() == MailFilter::GARBAGE) {
00124     FILE *fp = openTraceFile();
00125     if (fp != 0) {
00126       fprintf(fp, "\n");
00127       fprintf(fp, "From %s\n", SpamUtil().trimEnd(mFromNoColon));
00128       fprintf(fp, "From: %s\n", SpamUtil().trimEnd(mFrom));
00129       fprintf(fp, "To: %s\n", SpamUtil().trimEnd(mTo));
00130       fprintf(fp, "Subject: %s\n", SpamUtil().trimEnd(mSubject));
00131       fprintf(fp, "Date: %s\n", SpamUtil().trimEnd(mDate));
00132       fprintf(fp, "Reason-its-garbage: %s\n", SpamUtil().trimEnd(mReason));
00133       fclose(fp);
00134     }
00135   }
00136 }


Member Function Documentation

FILE * HeaderInfo::openTraceFile  )  [private]
 

Open the garbage_trace file. If the file is larger than MAX_FILE_SIZE it will be truncated.

Definition at line 78 of file HeaderInfo.C.

References Logger::getLogger(), and Logger::log().

Referenced by ~HeaderInfo().

00079 {
00080   const char *traceFileName = "garbage_trace";
00081   const size_t MAX_FILE_SIZE = 50 * 1024; // file size in K bytes
00082   Logger log = pLogger->getLogger("HeaderInfo");
00083   char msgbuf[128];
00084   FILE *fp = 0;
00085   char *mode = "a"; // open for append
00086   if ((fp = fopen(traceFileName, mode)) != 0) {
00087     int fileSize = SpamUtil().getFileSize( fp, traceFileName, msgbuf );
00088     if (fileSize >= 0) {
00089       if (fileSize > MAX_FILE_SIZE) {
00090         mode = "w"; // open for truncate
00091         fclose(fp);
00092         // open and truncate the file
00093         if ((fp = fopen(traceFileName, mode)) == 0) {
00094           char *err_reason = strerror( errno);
00095           sprintf( msgbuf, "could not re-open %s.  Reason: %s", 
00096                    traceFileName, err_reason );
00097           log.log(Logger::ERROR, "openTraceFile", msgbuf);
00098         }
00099       }
00100     }
00101     else { // error getting stat on file
00102       log.log(Logger::ERROR, "openTraceFile", msgbuf);
00103     }
00104   }
00105   else { // error opening file
00106     char *err_reason = strerror( errno);
00107     sprintf( msgbuf, "could not open %s.  Reason: %s", 
00108              traceFileName, err_reason );
00109     log.log(Logger::ERROR, "openTraceFile", msgbuf);
00110   }
00111 
00112   return fp;
00113 } // openTraceFile

void HeaderInfo::subject const char *  pBuf  ) 
 

Copy the subject into a local buffer and set the a flag which indicates that the subject has been found.

Definition at line 59 of file HeaderInfo.C.

00060 {
00061   if (pBuf != 0) {
00062     strncpy(mSubject, pBuf, sizeof(mSubject) );
00063     if (mSubject[0] == '\0') {
00064       mSubject[0] = ' ';
00065       mSubject[1] = '\0';
00066     }
00067     else {
00068       SpamUtil().trimEnd(mSubject);
00069     }
00070   }
00071 } // subject


Member Data Documentation

const bool HeaderInfo::mDoTrace [private]
 

mDoTrade: true = generate a garbage trace message

Definition at line 54 of file HeaderInfo.h.

Referenced by ~HeaderInfo().


The documentation for this class was generated from the following files:
Generated on Sat Mar 27 13:07:38 2004 for Mail Filter by doxygen 1.3.3