Crossfire Server, Trunk
CFMail.py
Go to the documentation of this file.
1 # CFMail.py - CFMail class
2 # Rewritten to use CFSqlDb
3 
4 import Crossfire
5 import CFSqlDb as cfdb
6 
7 class CFMail:
8  def __init__(self):
9  self.maildb = cfdb.open()
10 
11  def init_schema(self):
12  self.maildb.execute("CREATE TABLE IF NOT EXISTS mail ('recipient' TEXT, 'sender' TEXT, 'date' DATE, 'type' INT, 'message' TEXT);")
13 
14  def __enter__(self):
15  return self
16 
17  def __exit__(self, exc_type, exc_value, traceback):
18  self.close()
19 
20  def send(self, type, toname, fromname, message):
21  # type: 1=mailscoll, 2=newsletter, 3=mailwarning
22  self.maildb.execute("INSERT INTO mail VALUES (?, ?, datetime('now'), ?, ?);", (toname, fromname, type, message))
23 
24  def receive(self, toname):
25  c = self.maildb.cursor()
26  c.execute("SELECT type, sender, message FROM mail WHERE recipient=?;", (toname,))
27  mail = list()
28  for el in c.fetchall():
29  mail.append(el)
30  c.execute("DELETE FROM mail WHERE recipient=?;", (toname,))
31  return mail
32 
33  def countmail(self, toname):
34  c = self.maildb.cursor()
35  c.execute("SELECT COUNT(*) FROM mail WHERE recipient=?;", (toname,))
36  return c.fetchone()[0]
37 
38  def close(self):
39  self.maildb.commit()
40  self.maildb.close()
guildoracle.list
list
Definition: guildoracle.py:87
CFMail.CFMail.receive
def receive(self, toname)
Definition: CFMail.py:24
CFMail.CFMail.send
def send(self, type, toname, fromname, message)
Definition: CFMail.py:20
CFMail.CFMail
Definition: CFMail.py:7
CFMail.CFMail.__init__
def __init__(self)
Definition: CFMail.py:8
CFMail.CFMail.close
def close(self)
Definition: CFMail.py:38
CFMail.CFMail.__enter__
def __enter__(self)
Definition: CFMail.py:14
CFMail.CFMail.countmail
def countmail(self, toname)
Definition: CFMail.py:33
CFMail.CFMail.__exit__
def __exit__(self, exc_type, exc_value, traceback)
Definition: CFMail.py:17
CFMail.CFMail.maildb
maildb
Definition: CFMail.py:9
CFMail.CFMail.init_schema
def init_schema(self)
Definition: CFMail.py:11