// http2email/ImapConnection.hh // This file is part of Decimail; see http://decimail.org/ // (C) 2006 Philip Endecott // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef ImapConnection_hh #define ImapConnection_hh #include #include "TcpClientSocket.hh" #include "SessionId.hh" class ImapConnection { public: ImapConnection(std::string host, short port); SessionId get_id() const {return id;} void send(std::string cmd) {socket.writeall(cmd);} std::string get(void) { float timeout=60; std::string s; while(1) { bool readable = wait_until(socket.readable(),timeout); if (!readable) { return s; } // libpbe now has something called read_until_idle that could be used here. std::string t = socket.readsome(); if (t=="") { if (s!="") { return s; } throw "Imap connection is closed"; } s += t; timeout=0.05; } } void touch(void) {last_access_time = time(NULL);} time_t get_last_access_time(void) const {return last_access_time;} private: pbe::TcpClientSocket socket; SessionId id; time_t last_access_time; }; #endif