#include #include #include #include #include #include #include #include #ifndef WIN32 #include #endif #include #include #include #include #include "getrfc.h" const char *getrfct::getpath() { return fp.getpath(); } getrfct::getrfct() { cached_nr=0xffffffff; rfcm.data=(char *)NULL; mimestruct=(mimestructt *)NULL; index=header=-1; opened=FALSE; } getrfct::~getrfct() { clear_cached(); if(index>=0) ::close(index); if(header>=0) ::close(header); } dword getrfct::get_number_of_messages() { if(index<0) return 0; return filelength(index)/sizeof fi; } bool getrfct::close() { clear_cached(); if(index>=0) ::close(index); if(header>=0) ::close(header); index=header=-1; opened=FALSE; return FALSE; } bool getrfct::open_files() { char filename[DIRLEN]; if(opened) close(); snprintf(filename, DIRLEN, "%sindex", fp.getpath()); index=::open(filename, O_RDWR|O_BINARY|O_CREAT, S_IREAD|S_IWRITE); snprintf(filename, DIRLEN, "%sheader", fp.getpath()); header=::open(filename, O_RDWR|O_BINARY|O_CREAT, S_IREAD|S_IWRITE); return index<0 || header<0; } bool getrfct::open_mail(const std::string &name, const std::string &subfolder) { std::string folder_name; if(subfolder=="") { folder_name="0@"; // default subfolder folder_name+=name; } else folder_name=subfolder+"@"+name; fp.setname(folder_name); fp.read(); return open_files(); } bool getrfct::open_news(const std::string &name) { fp.setname(name); fp.read(); return open_files(); } // // Binary search for uids // bool getrfct::search_uid(dword uid, dword &nr) { if(index<0) return TRUE; dword number_of_messages=get_number_of_messages(); #if 1 dword begin=0, end=number_of_messages; while(beginuid end=nr; } #else for(nr=0; nrmimeparse(rfcm); cached_structure=TRUE; } return FALSE; }