Debian Codegraph @

src/bnetd/mail.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2001,2006 Dizzy
3 * Copyright (C) 2004 Donny Redmond ([email protected])
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20
21 /*****/
22 #ifndef INCLUDED_PVPGN_BNETD_MAIL
23 #define INCLUDED_PVPGN_BNETD_MAIL
24
25
26 #define MAX_FUNC_LEN 10
27 #define MAX_MAIL_QUOTA 10
28 #define MAIL_FUNC_SEND 1
29 #define MAIL_FUNC_READ 2
30 #define MAIL_FUNC_DELETE 3
31 #define MAIL_FUNC_UNKNOWN 4
32
33
34 #include <string>
35 #include <stdexcept>
36 #include <deque>
37 #include <ctime>
38
39 #include "compat/pdir.h"
40 #include "connection.h"
41
42 namespace pvpgn
43 {
44
45 namespace bnetd
46 {
47
48 class Mail
49 {
50 public:
51 Mail(const std::string& sender, const std::string& mess, const std::time_t timestamp);
52 ~Mail() throw();
53
54 const std::string& sender() const;
55 const std::string& message() const;
56 const std::time_t& timestamp() const;
57
58 private:
59 const std::string sender_;
60 const std::string message_;
61 const std::time_t timestamp_;
62 };
63
64 typedef std::deque<Mail> MailList;
65
66 class Mailbox {
67 public:
68 class ReadError : public std::runtime_error {
69 public:
70 ReadError(const std::string& mess)
71 :std::runtime_error(mess) {}
72 ~ReadError() throw() {}
73 };
74
75 class DeliverError : public std::runtime_error {
76 public:
77 DeliverError(const std::string& mess)
78 :std::runtime_error(mess) {}
79 ~DeliverError() throw() {}
80 };
81
82 explicit Mailbox(unsigned uid);
83 ~Mailbox() throw();
84
85 unsigned size() const;
86 bool empty() const;
87 void deliver(const std::string& sender, const std::string& mess);
88 Mail read(unsigned int) const;
89 void readAll(MailList& dest) const;
90 void erase(unsigned int);
91 void clear();
92
93 private:
94 unsigned uid;
95 const std::string path;
96 mutable Directory mdir;
97
98 std::string buildPath(const std::string& root) const;
99 void createOpenDir();
100 Mail read(const std::string& fname, const std::time_t& timestamp) const;
101
102 Mailbox(const Mailbox&);
103 Mailbox& operator=(const Mailbox&);
104 };
105
106
107 extern int handle_mail_command(t_connection *, char const *);
108 extern unsigned check_mail(t_connection const * c);
109
110 }
111
112 }
113
114 #endif