// imapd/Session.hh // This file is part of Decimail; see http://decimail.org // (C) 2004-2007 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 Imapd_Session_hh #define Imapd_Session_hh #include "Exception.hh" #include "FileDescriptor.hh" #include "ImapdDb.hh" #include #include #include #include #include namespace Imapd { class CommandParser; class CloseConnection: public pbe::Exception { public: void report(ostream& strm) const; }; class Session { public: Session(pbe::FileDescriptor& i, pbe::FileDescriptor& o); ~Session(); void run(void); pbe::FileDescriptor& get_in_fd(void) { return in_fd; } void monitor_notifications(void); void send_any_unilateral_updates(bool block); void respond_ok(std::string tag, std::string msg); void respond_no(std::string tag, std::string msg); void respond_bad(std::string tag, std::string msg); void respond_untagged(std::string msg); void send_continuation_request(void); void flush(void); enum State { non_auth=1, auth=2, selected=4 }; void set_state(State s) { state=s; } State get_state(void) const { return state; } void check_state(int allowed_states); ImapdDb& get_db(void) { return db; } void set_username(std::string u); void clear_username(void) { username=""; } std::string get_username(void) const { return username; } void set_mailbox(std::string m); void clear_mailbox(void) { mailbox=""; } std::string get_mailbox(void) const { return mailbox; } std::string get_mailbox_query(void) const { return mailbox_query; } std::vector seqnum_to_msgid; std::map msgid_to_seqnum; void get_msg_ids(void); void prefetch_messages(const list& msg_ids); typedef boost::shared_ptr message_ptr_t; message_ptr_t get_message(int msg_id) { return cached_messages[msg_id]; } const int num; typedef boost::mutex mutex_t; mutex_t db_and_output_mutex; // Prevent simultaneous access to the per-session database // connection or to output to the client socket by the two // threads. private: static int next_num; pbe::FileDescriptor& in_fd; pbe::FileDescriptor& out_fd; pbe::FileDescriptor::ostream out_strm; boost::scoped_ptr parser; // only a pointer to avoid circular dependencies State state; ImapdDb db; std::string username; std::string mailbox; std::string mailbox_query; typedef std::map cached_messages_t; cached_messages_t cached_messages; bool unreported_messages; void respond(std::string tag, std::string response, std::string msg); bool closing; }; }; #endif