EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MailDB Class Reference

#include "MailDB.h"

Inheritance diagram for MailDB:
Collaboration diagram for MailDB:

Public Member Functions

PyRepGetLabels (int characterID) const
 
PyStringGetMailBody (int id) const
 
void SetMailUnread (int id)
 
void SetMailRead (int id)
 
void SetMailsUnread (std::vector< int32 > ids)
 
void SetMailsRead (std::vector< int32 > ids)
 
void MarkAllAsRead (uint32 characterID)
 
void MarkAllAsUnread (uint32 characterID)
 
bool CreateLabel (int characterID, Call_CreateLabel &args, uint32 &newID) const
 
void DeleteLabel (int characterID, int labelID) const
 
void EditLabel (int characterID, Call_EditLabel &args) const
 
void ApplyLabel (int32 messageID, int labelID)
 
void ApplyLabels (std::vector< int32 > messageIDs, int labelID)
 
void MarkAllAsReadByLabel (uint32 characterID, int labelID)
 
void MarkAllAsUnreadByLabel (uint32 characterID, int labelID)
 
void RemoveLabels (std::vector< int32 > messageIDs, int labelID)
 
void DeleteMail (int32 messageID)
 
void EmptyTrash (uint32 characterID)
 
void MoveAllFromTrash (uint32 characterID)
 
void MoveAllToTrash (uint32 characterID)
 
void MoveFromTrash (int32 messageID)
 
void MoveToTrash (int32 messageID)
 
void MoveToTrashByLabel (int32 characterID, int32 labelID)
 
PyDictGetJoinedMailingLists (uint32 characterID)
 
uint32 CreateMailingList (uint32 creator, std::string name, int32 defaultAccess, int32 defaultMemberAccess, int32 cost)
 
void JoinMailingList (uint32 characterID, std::string name)
 
void LeaveMailingList (uint32 characterID, int32 listID)
 
void DeleteMailingList (uint32 characterID, int32 listID)
 
PyDictGetMailingListMembers (int32 listID)
 
void MailingListSetEntityAccess (int32 entity, int32 access, int32 listID)
 
void MailingListClearEntityAccess (int32 entity, int32 listID)
 
void SetMailingListDefaultAccess (int32 listID, int32 defaultAccess, int32 defaultMemberAccess, int32 cost)
 
PyObjectMailingListGetSettings (int32 listID)
 
void ApplyStatusMasks (std::vector< int32 > messageIDs, int mask)
 
void RemoveStatusMasks (std::vector< int32 > messageIDs, int mask)
 
void ApplyStatusMask (int32 messageID, int mask)
 
void RemoveStatusMask (int32 messageID, int mask)
 
void ApplyLabelMask (int32 messageID, int mask)
 
void ApplyLabelMasks (std::vector< int32 > messageIDs, int mask)
 
void RemoveLabelMask (int32 messageID, int mask)
 
void RemoveLabelMasks (std::vector< int32 > messageIDs, int mask)
 
int SendMail (int sender, std::vector< int > &toCharacterIDs, int toListID, int toCorpOrAllianceID, std::string &title, std::string &body, int isReplyTo, int isForwardedFrom)
 
PyRepGetNewMail (int charId)
 
PyRepGetMailStatus (int charId)
 
- Public Member Functions inherited from ServiceDB
uint32 GetStationOwner (uint32 stationID)
 

Static Protected Member Functions

static int BitFromLabelID (int id)
 
- Static Protected Member Functions inherited from ServiceDB
static uint32 CreateNewAccount (const char *login, const char *pass, const char *passHash, int64 role)
 

Additional Inherited Members

- Static Public Member Functions inherited from ServiceDB
static bool GetAccountInformation (CryptoChallengePacket &ccp, AccountData &aData, std::string &failMsg)
 
static bool UpdateAccountHash (const char *username, std::string &hash)
 
static bool IncrementLoginCount (uint32 accountID)
 
static void UpdatePassword (uint32 accountID, const char *pass)
 
static void SaveKillOrLoss (CharKillData &data)
 
static bool GetConstant (const char *name, uint32 &into)
 
static void SetServerOnlineStatus (bool online=false)
 
static void SetCharacterOnlineStatus (uint32 char_id, bool online=false)
 
static void SetAccountOnlineStatus (uint32 accountID, bool online=false)
 
static void SetAccountBanStatus (uint32 accountID, bool banned=false)
 
static void SaveServerStats (double threads, float rss, float vm, float user, float kernel, uint32 items, uint32 bubbles)
 
static uint32 SetClientSeed ()
 
static PyRepLookupChars (const char *match, bool exact=false)
 
static PyRepLookupOwners (const char *match, bool exact=false)
 
static PyRepLookupCorporations (const std::string &)
 
static PyRepLookupFactions (const std::string &)
 
static PyRepLookupCorporationTickers (const std::string &)
 
static PyRepLookupStations (const std::string &)
 
static PyRepLookupKnownLocationsByGroup (const std::string &, uint32)
 
static PyRepPrimeOwners (std::vector< int32 > &itemIDs)
 
static bool ValidateAccountName (CryptoChallengePacket &ccp, std::string &failMsg)
 
static void GetCorpHangarNames (uint32 corpID, std::map< uint8, std::string > &hangarNames)
 
- Protected Member Functions inherited from ServiceDB
void ProcessStringChange (const char *key, const std::string &oldValue, std::string newValue, PyDict *notif, std::vector< std::string > &dbQ)
 
void ProcessRealChange (const char *key, double oldValue, double newValue, PyDict *notif, std::vector< std::string > &dbQ)
 
void ProcessIntChange (const char *key, uint32 oldValue, uint32 newValue, PyDict *notif, std::vector< std::string > &dbQ)
 
void ProcessLongChange (const char *key, int64 oldValue, int64 newValue, PyDict *notif, std::vector< std::string > &dbQ)
 

Detailed Description

Definition at line 36 of file MailDB.h.

Member Function Documentation

void MailDB::ApplyLabel ( int32  messageID,
int  labelID 
)

Definition at line 368 of file MailDB.cpp.

References ApplyLabelMask(), and BitFromLabelID().

369 {
370  int bit = BitFromLabelID(labelID);
371  ApplyLabelMask(messageID, (1 << bit));
372 }
static int BitFromLabelID(int id)
Definition: MailDB.cpp:595
void ApplyLabelMask(int32 messageID, int mask)
Definition: MailDB.cpp:514

Here is the call graph for this function:

void MailDB::ApplyLabelMask ( int32  messageID,
int  mask 
)

Definition at line 514 of file MailDB.cpp.

References codelog, and sDatabase.

Referenced by ApplyLabel().

515 {
516 
517  DBerror err;
518  if (!sDatabase.RunQuery(err,
519  " UPDATE mailStatus "
520  " SET labelMask = (labelMask | %u) "
521  " WHERE messageID = %u;" , mask, messageID))
522  {
523  codelog(DATABASE__ERROR, " Failed to apply label mask to message" );
524  }
525 
526 }
#define sDatabase
Definition: dbcore.h:199
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39

Here is the caller graph for this function:

void MailDB::ApplyLabelMasks ( std::vector< int32 messageIDs,
int  mask 
)

Definition at line 540 of file MailDB.cpp.

References _log, DBerror::c_str(), codelog, and sDatabase.

Referenced by ApplyLabels().

541 {
542  DBerror err;
543 
544  if (messageIDs.size() == 0) {
545  return;
546  }
547 
548  std::ostringstream query;
549  query << " UPDATE mailStatus SET labelMask = labelMask | " << mask << " " ;
550 
551  query << " WHERE messageID = " << messageIDs[0];
552 
553  for (int i = 1; i < messageIDs.size(); i++) {
554  query << " OR messageID = " << messageIDs[i];
555  }
556 
557  _log(DATABASE__ERROR, query.str().c_str());
558 
559 
560  if (!sDatabase.RunQuery(err, query.str().c_str()))
561  {
562  codelog(DATABASE__ERROR, " Failed to apply labels" );
563  return;
564  }
565 }
#define sDatabase
Definition: dbcore.h:199
#define _log(type, fmt,...)
Definition: logsys.h:124
const char * c_str() const
Definition: dbcore.h:48
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39

Here is the call graph for this function:

Here is the caller graph for this function:

void MailDB::ApplyLabels ( std::vector< int32 messageIDs,
int  labelID 
)

Definition at line 276 of file MailDB.cpp.

References ApplyLabelMasks(), and BitFromLabelID().

277 {
278  int bit = BitFromLabelID(labelID);
279  ApplyLabelMasks(messageIDs, (1 << bit));
280 }
static int BitFromLabelID(int id)
Definition: MailDB.cpp:595
void ApplyLabelMasks(std::vector< int32 > messageIDs, int mask)
Definition: MailDB.cpp:540

Here is the call graph for this function:

void MailDB::ApplyStatusMask ( int32  messageID,
int  mask 
)

Definition at line 490 of file MailDB.cpp.

References codelog, and sDatabase.

Referenced by SetMailRead().

491 {
492  DBerror err;
493  if (!sDatabase.RunQuery(err,
494  " UPDATE mailStatus "
495  " SET statusMask = statusMask | %u "
496  " WHERE messageID = %u" , mask, messageID)) {
497  codelog(DATABASE__ERROR, " Failed to apply status mask" );
498  }
499 }
#define sDatabase
Definition: dbcore.h:199
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39

Here is the caller graph for this function:

void MailDB::ApplyStatusMasks ( std::vector< int32 messageIDs,
int  mask 
)

Definition at line 448 of file MailDB.cpp.

References DBerror::c_str(), codelog, and sDatabase.

Referenced by SetMailsRead().

449 {
450  if (messageIDs.size() == 0) {
451  return;
452  }
453 
454  std::ostringstream query;
455 
456  query << " UPDATE mailStatus SET statusMask = statusMask | " << mask << " WHERE " ;
457  query << " messageID = " << messageIDs[0];
458  for (int i = 1; i < messageIDs.size(); i++) {
459  query << " OR messageID = " << messageIDs[i];
460  }
461 
462  DBerror err;
463 
464  if (!sDatabase.RunQuery(err, query.str().c_str())) {
465  codelog(DATABASE__ERROR, " Failed apply status mask" );
466  }
467 }
#define sDatabase
Definition: dbcore.h:199
const char * c_str() const
Definition: dbcore.h:48
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39

Here is the call graph for this function:

Here is the caller graph for this function:

int MailDB::BitFromLabelID ( int  id)
staticprotected

Definition at line 595 of file MailDB.cpp.

References sLog.

Referenced by ApplyLabel(), ApplyLabels(), DeleteLabel(), EditLabel(), MarkAllAsReadByLabel(), MarkAllAsUnreadByLabel(), MoveToTrashByLabel(), and RemoveLabels().

596 {
597  // lets hope the compiler can do this better; I guess it still beats a floating point log, though
598  for (int i = 0; i < (sizeof(int)*8); i++)
599  if ((id & (1 << i)) > 0)
600  return i;
601 
602  // This just gets rid of a warning, code execution should never reach here.
603  sLog.Error(" MailDB::BitFromLabelID" , " ERROR: Could not get bit." );
604  return 0;
605 }
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250

Here is the caller graph for this function:

bool MailDB::CreateLabel ( int  characterID,
Call_CreateLabel &  args,
uint32 newID 
) const

Definition at line 304 of file MailDB.cpp.

References DBerror::c_str(), codelog, DBResultRow::GetInt(), DBQueryResult::GetRow(), DBQueryResult::GetRowCount(), and sDatabase.

305 {
306  // we need to get the next free bit index; can't avoid a SELECT
307  DBQueryResult res;
308  sDatabase.RunQuery(res, " SELECT bit FROM mailLabel WHERE ownerID = %u ORDER BY bit DESC LIMIT 1" , characterID);
309 
310  // 6 is a guessed default; there are some hardcoded labels that we don't have the details on yet
311  int bit = 6;
312 
313  if (res.GetRowCount() > 0)
314  {
315  DBResultRow row;
316  res.GetRow(row);
317  // we want the next one, not the current one, so +1
318  bit = row.GetInt(0) + 1;
319  }
320 
321  DBerror error;
322  if (!sDatabase.RunQuery(error, " INSERT INTO mailLabel (bit, name, color, ownerID) VALUES (%u, '%s', %u, %u)" , bit, args.name.c_str(), args.color, characterID))
323  {
324  codelog(DATABASE__ERROR, " Failed to insert new mail label into database" );
325  // since this is an out parameter, make sure we assign this even in case of an error
326  newID = 0;
327  return false;
328  }
329 
330  // the client wants the power of 2, not the bitset index
331  newID = (uint32)pow((float)2, bit);
332  return true;
333 }
#define sDatabase
Definition: dbcore.h:199
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
* args
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
#define codelog(type, fmt,...)
Definition: logsys.h:128
unsigned __int32 uint32
Definition: eve-compat.h:50
size_t GetRowCount()
Definition: dbcore.h:72
Definition: dbcore.h:39

Here is the call graph for this function:

uint32 MailDB::CreateMailingList ( uint32  creator,
std::string  name,
int32  defaultAccess,
int32  defaultMemberAccess,
int32  cost 
)

Definition at line 659 of file MailDB.cpp.

References DBerror::c_str(), codelog, mailingListAllowed, mailingListMemberOwner, and sDatabase.

660 {
661  DBerror err;
662  uint32 id = 0;
663  uint32& idr = id;
664 
665  if (!sDatabase.RunQueryLID(err, idr,
666  " INSERT INTO mailList "
667  " (displayName, defaultAccess, defaultMemberAccess, cost) "
668  " VALUES( '%s', %u, %u, %u) " , name.c_str(), defaultAccess,
669  defaultMemberAccess, cost))
670  {
671  codelog(DATABASE__ERROR, " Failed to create mailing list" );
672  return -1;
673  }
674 
675  if (!sDatabase.RunQuery(err,
676  " INSERT INTO mailListUsers "
677  " (listID, characterID, role, access) "
678  " VALUES(%u, %u, %u, %u)" , id, creator, mailingListMemberOwner,
680  {
681  codelog(DATABASE__ERROR, " Failed to insert owner of mailing list" );
682  return -1;
683  }
684 
685  return id;
686 }
#define sDatabase
Definition: dbcore.h:199
#define mailingListMemberOwner
Definition: EVE_Mail.h:29
const char * c_str() const
Definition: dbcore.h:48
#define codelog(type, fmt,...)
Definition: logsys.h:128
unsigned __int32 uint32
Definition: eve-compat.h:50
#define mailingListAllowed
Definition: EVE_Mail.h:25
Definition: dbcore.h:39

Here is the call graph for this function:

void MailDB::DeleteLabel ( int  characterID,
int  labelID 
) const

Definition at line 335 of file MailDB.cpp.

References BitFromLabelID(), codelog, and sDatabase.

336 {
337  int bit = BitFromLabelID(labelID);
338  DBerror err;
339  if (!sDatabase.RunQuery(err,
340  " UPDATE mailMessage "
341  " SET labelMask = labelMask & ~(1 << ~%u) "
342  " WHERE (labelMask & (1 << %u)) > 0 "
343  " AND toCharacterIDs LIKE '%%%u%%';" , bit, bit, characterID))
344  {
345  codelog(DATABASE__ERROR, " Failed to delete label" );
346  return;
347  }
348 
349  sDatabase.RunQuery(err,
350  " DELETE FROM mailLabel "
351  " WHERE ownerID = %u AND bit = %u;" , characterID, bit);
352 }
#define sDatabase
Definition: dbcore.h:199
static int BitFromLabelID(int id)
Definition: MailDB.cpp:595
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39

Here is the call graph for this function:

void MailDB::DeleteMail ( int32  messageID)

Definition at line 374 of file MailDB.cpp.

References codelog, and sDatabase.

375 {
376  DBerror err;
377 
378  if (!sDatabase.RunQuery(err,
379  " DELETE FROM mailStatus "
380  " WHERE messageID = %u;" , messageID)) {
381 
382  codelog(DATABASE__ERROR, " Failed to delete mail" );
383  }
384 }
#define sDatabase
Definition: dbcore.h:199
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39
void MailDB::DeleteMailingList ( uint32  characterID,
int32  listID 
)

Definition at line 773 of file MailDB.cpp.

774 {
775 
776 }
void MailDB::EditLabel ( int  characterID,
Call_EditLabel &  args 
) const

Definition at line 354 of file MailDB.cpp.

References BitFromLabelID(), DBerror::c_str(), and sDatabase.

355 {
356  int bit = BitFromLabelID(args.labelId);
357 
358  DBerror error;
359  if (args.name.length() == 0) {
360  sDatabase.RunQuery(error, " UPDATE mailLabel SET color = %u WHERE bit = %u AND ownerID = %u" , args.color, bit, characterID);
361  } else if (args.color == -1) {
362  sDatabase.RunQuery(error, " UPDATE mailLabel SET name = '%s' WHERE bit = %u AND ownerID = %u" , args.name.c_str(), bit, characterID);
363  } else {
364  sDatabase.RunQuery(error, " UPDATE mailLabel SET name = '%s', color = %u WHERE bit = %u AND ownerID = %u" , args.name.c_str(), args.color, bit, characterID);
365  }
366 }
#define sDatabase
Definition: dbcore.h:199
static int BitFromLabelID(int id)
Definition: MailDB.cpp:595
* args
Definition: dbcore.h:39

Here is the call graph for this function:

void MailDB::EmptyTrash ( uint32  characterID)

Definition at line 386 of file MailDB.cpp.

References codelog, mailStatusMaskTrashed, and sDatabase.

387 {
388  DBerror err;
389  if (!sDatabase.RunQuery(err,
390  " DELETE FROM mailMessage "
391  " WHERE senderID = %u "
392  " AND (statusMask & %u) > 0;" , characterID, mailStatusMaskTrashed)) {
393  codelog(DATABASE__ERROR, " Failed to deleted trash mails" );
394  }
395 }
#define sDatabase
Definition: dbcore.h:199
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39
PyDict * MailDB::GetJoinedMailingLists ( uint32  characterID)

Definition at line 607 of file MailDB.cpp.

References codelog, DBResultRow::GetInt(), DBQueryResult::GetRow(), DBResultRow::GetText(), mailingListMemberMuted, mailingListMemberOperator, mailingListMemberOwner, sDatabase, PyDict::SetItem(), and PyDict::SetItemString().

608 {
609 
610  // @NOTE: May have to util.keyval this??j?
611  DBQueryResult res;
612 
613  if (!sDatabase.RunQuery(res,
614  " SELECT l.id, l.displayName, l.defaultAccess, l.defaultMemberAccess, l.cost,"
615  " u.listID, u.characterID, u.role, u.access"
616  " FROM mailListUsers AS u "
617  " LEFT JOIN mailList AS l ON l.id = u.listID "
618  " WHERE u.characterID = %u" , characterID))
619  {
620  codelog(DATABASE__ERROR, " Failed to get joined mailing lists" );
621  return nullptr;
622  }
623 
624  DBResultRow row;
625  PyDict *ret = new PyDict();
626  while (res.GetRow(row))
627  {
628  PyDict *dict = new PyDict();
629 
630  dict->SetItemString(" displayName" , new PyString(row.GetText(1)));
631 
632  int32 role = row.GetInt(7);
633  switch (role)
634  {
635  case mailingListMemberMuted: {
636  dict->SetItemString(" isMuted" , new PyBool(true));
637  dict->SetItemString(" isOwner" , new PyBool(false));
638  dict->SetItemString(" isOperator" , new PyBool(false));
639  } break;
641  dict->SetItemString(" isMuted" , new PyBool(false));
642  dict->SetItemString(" isOwner" , new PyBool(false));
643  dict->SetItemString(" isOperator" , new PyBool(true));
644  } break;
645  case mailingListMemberOwner: {
646  dict->SetItemString(" isMuted" , new PyBool(false));
647  dict->SetItemString(" isOwner" , new PyBool(true));
648  dict->SetItemString(" isOperator" , new PyBool(false));
649  } break;
650  }
651 
652  ret->SetItem(new PyInt(row.GetInt(0)), new PyObject(" util.KeyVal" , dict));
653  }
654 
655  return ret;
656 }
#define sDatabase
Definition: dbcore.h:199
const char * GetText(uint32 index) const
Definition: dbcore.h:104
Python string.
Definition: PyRep.h:430
#define mailingListMemberMuted
Definition: EVE_Mail.h:26
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
Python's dictionary.
Definition: PyRep.h:719
#define mailingListMemberOwner
Definition: EVE_Mail.h:29
signed __int32 int32
Definition: eve-compat.h:49
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
Python boolean.
Definition: PyRep.h:323
Python object.
Definition: PyRep.h:826
#define codelog(type, fmt,...)
Definition: logsys.h:128
#define mailingListMemberOperator
Definition: EVE_Mail.h:28
Python integer.
Definition: PyRep.h:231
void SetItem(PyRep *key, PyRep *value)
SetItem adds or sets a database entry.
Definition: PyRep.cpp:713
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812

Here is the call graph for this function:

PyRep * MailDB::GetLabels ( int  characterID) const

Definition at line 282 of file MailDB.cpp.

References DBResultRow::GetInt(), DBQueryResult::GetRow(), DBResultRow::GetText(), sDatabase, and PyDict::SetItem().

283 {
284  DBQueryResult res;
285  if (!sDatabase.RunQuery(res, " SELECT bit, name, color FROM mailLabel WHERE ownerID = %u" , characterID))
286  return nullptr;
287 
288  PyDict* ret = new PyDict();
289 
290  DBResultRow row;
291  while (res.GetRow(row))
292  {
293  MailLabel label;
294  label.id = (int)pow((float)2, row.GetInt(0));
295  label.name = row.GetText(1);
296  label.color = row.GetInt(2);
297 
298  ret->SetItem(new PyInt(label.id), label.Encode());
299  }
300 
301  return ret;
302 }
#define sDatabase
Definition: dbcore.h:199
const char * GetText(uint32 index) const
Definition: dbcore.h:104
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
Python's dictionary.
Definition: PyRep.h:719
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
Python integer.
Definition: PyRep.h:231
void SetItem(PyRep *key, PyRep *value)
SetItem adds or sets a database entry.
Definition: PyRep.cpp:713

Here is the call graph for this function:

PyString * MailDB::GetMailBody ( int  id) const

Definition at line 151 of file MailDB.cpp.

References DBResultRow::ColumnLength(), DBQueryResult::GetRow(), DBQueryResult::GetRowCount(), DBResultRow::GetText(), DBResultRow::IsNull(), and sDatabase.

152 {
153  DBQueryResult res;
154  if (!sDatabase.RunQuery(res, " SELECT body FROM mailMessage WHERE messageID = %u" , id))
155  return nullptr;
156  if (res.GetRowCount() <= 0)
157  return nullptr;
158 
159  DBResultRow row;
160  if (!res.GetRow(row) || row.IsNull(0))
161  return nullptr;
162 
163  return new PyString(row.GetText(0), row.ColumnLength(0));
164 }
#define sDatabase
Definition: dbcore.h:199
uint32 ColumnLength(uint32 index) const
Definition: dbcore.cpp:624
const char * GetText(uint32 index) const
Definition: dbcore.h:104
Python string.
Definition: PyRep.h:430
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
bool IsNull(uint32 index) const
Definition: dbcore.h:102
size_t GetRowCount()
Definition: dbcore.h:72

Here is the call graph for this function:

PyDict * MailDB::GetMailingListMembers ( int32  listID)

Definition at line 688 of file MailDB.cpp.

References codelog, DBResultRow::GetInt(), DBQueryResult::GetRow(), sDatabase, and PyDict::SetItem().

689 {
690  DBQueryResult res;
691  if (!sDatabase.RunQuery(res,
692  " SELECT listID, characterID, role, access FROM mailListUsers "
693  " WHERE listID = %u" , listID))
694  {
695  codelog(DATABASE__ERROR, " Failed to get mailing list members" );
696  return nullptr;
697  }
698 
699  DBResultRow row;
700  PyDict *dict = new PyDict();
701 
702  while (res.GetRow(row))
703  {
704  dict->SetItem(new PyInt(row.GetInt(1)), new PyInt(row.GetInt(2)));
705  }
706  return dict;
707 }
#define sDatabase
Definition: dbcore.h:199
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
Python's dictionary.
Definition: PyRep.h:719
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
#define codelog(type, fmt,...)
Definition: logsys.h:128
Python integer.
Definition: PyRep.h:231
void SetItem(PyRep *key, PyRep *value)
SetItem adds or sets a database entry.
Definition: PyRep.cpp:713

Here is the call graph for this function:

PyRep * MailDB::GetMailStatus ( int  charId)

Definition at line 34 of file MailDB.cpp.

References codelog, DBResultToCRowset(), and sDatabase.

35 {
36  DBQueryResult res;
37  if (!sDatabase.RunQuery(res,
38  " SELECT messageID, statusMask, labelMask "
39  " FROM mailStatus"
40  " WHERE characterID = %u" , charId)) {
41  codelog(DATABASE__ERROR, " Failed to get mail status" );
42  return nullptr;
43  }
44  return DBResultToCRowset(res);
45 }
#define sDatabase
Definition: dbcore.h:199
PyObjectEx * DBResultToCRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:402
#define codelog(type, fmt,...)
Definition: logsys.h:128

Here is the call graph for this function:

PyRep * MailDB::GetNewMail ( int  charId)

Definition at line 47 of file MailDB.cpp.

References DBResultToCRowset(), and sDatabase.

48 {
49  DBQueryResult res;
50  if (!sDatabase.RunQuery(res,
51  " SELECT m.messageID, m.senderID, m.toCharacterIDs, m.toListID, "
52  " m.toCorpOrAllianceID, m.title, m.sentDate FROM mailStatus AS s"
53  " LEFT JOIN mailMessage AS m USING (messageID) "
54  " WHERE s.characterID = %u" , charId))
55  return nullptr;
56  return DBResultToCRowset(res);
57 }
#define sDatabase
Definition: dbcore.h:199
PyObjectEx * DBResultToCRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:402

Here is the call graph for this function:

void MailDB::JoinMailingList ( uint32  characterID,
std::string  name 
)

Definition at line 777 of file MailDB.cpp.

778 {
779 
780 }
void MailDB::LeaveMailingList ( uint32  characterID,
int32  listID 
)

Definition at line 781 of file MailDB.cpp.

782 {
783 
784 }
void MailDB::MailingListClearEntityAccess ( int32  entity,
int32  listID 
)

Definition at line 785 of file MailDB.cpp.

786 {
787 
788 }
PyObject * MailDB::MailingListGetSettings ( int32  listID)

Definition at line 710 of file MailDB.cpp.

References codelog, DBResultRow::GetInt(), DBQueryResult::GetRow(), sDatabase, PyDict::SetItem(), and PyDict::SetItemString().

711 {
712  PyDict *ret = new PyDict();
713 
714  // TODO(groove): Make this a join if possible
715 
716  DBQueryResult res;
717 
718  if (!sDatabase.RunQuery(res,
719  " SELECT id, displayName, defaultAccess, defaultMemberAccess, cost FROM mailList "
720  " WHERE id = %u" , listID))
721  {
722  codelog(DATABASE__ERROR, " Failed to get mailing list settings" );
723  return nullptr;
724  }
725  DBResultRow row;
726 
727  if (!res.GetRow(row)) {
728  codelog(DATABASE__ERROR, " mailList didn't give us a row" );
729  return nullptr;
730  }
731 
732 
733  ret->SetItemString(" defaultAccess" , new PyInt(row.GetInt(2)));
734  ret->SetItemString(" defaultMemberAccess" , new PyInt(row.GetInt(3)));
735 
736  DBQueryResult res2;
737 
738  if (!sDatabase.RunQuery(res,
739  " SELECT listID, characterID, role, access FROM mailListUsers "
740  " WHERE listID = %u" , listID))
741  {
742  codelog(DATABASE__ERROR, " Failed to get mailing list settings" );
743  return nullptr;
744  }
745 
746  PyDict *dict = new PyDict();
747 
748  ret->SetItemString(" access" , dict);
749 
750 
751  while (res.GetRow(row)) {
752  dict->SetItem(new PyInt(row.GetInt(1)), new PyInt(row.GetInt(3)));
753  }
754 
755  return new PyObject(" util.KeyVal" , ret);
756 }
#define sDatabase
Definition: dbcore.h:199
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
Python's dictionary.
Definition: PyRep.h:719
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
Python object.
Definition: PyRep.h:826
#define codelog(type, fmt,...)
Definition: logsys.h:128
Python integer.
Definition: PyRep.h:231
void SetItem(PyRep *key, PyRep *value)
SetItem adds or sets a database entry.
Definition: PyRep.cpp:713
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812

Here is the call graph for this function:

void MailDB::MailingListSetEntityAccess ( int32  entity,
int32  access,
int32  listID 
)

Definition at line 789 of file MailDB.cpp.

790 {
791 
792 }
void MailDB::MarkAllAsRead ( uint32  characterID)

Definition at line 200 of file MailDB.cpp.

References codelog, mailStatusMaskRead, and sDatabase.

201 {
202  DBerror err;
203 
204  if (!sDatabase.RunQuery(err,
205  " UPDATE mailMessage "
206  " SET statusMask = statusMask | %u "
207  " WHERE toCharacterIDs LIKE '%%%u%%'" , mailStatusMaskRead, characterID)) {
208  codelog(DATABASE__ERROR, " Failed to mark all as read" );
209  return;
210  }
211 }
#define sDatabase
Definition: dbcore.h:199
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39
void MailDB::MarkAllAsReadByLabel ( uint32  characterID,
int  labelID 
)

Definition at line 230 of file MailDB.cpp.

References BitFromLabelID(), codelog, and sDatabase.

231 {
232  int bit = BitFromLabelID(labelID);
233  DBerror err;
234 
235  if (!sDatabase.RunQuery(err,
236  " UPDATE mailMessage "
237  " SET statusMask = statusMask | %u "
238  " WHERE toCharacterIDs LIKE '%%%u%%' "
239  " AND (labelMask & (1 << %u)) > 0" , characterID, bit))
240  {
241  codelog(DATABASE__ERROR, " Failed to mark all as read by label" );
242  return;
243  }
244 }
#define sDatabase
Definition: dbcore.h:199
static int BitFromLabelID(int id)
Definition: MailDB.cpp:595
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39

Here is the call graph for this function:

void MailDB::MarkAllAsUnread ( uint32  characterID)

Definition at line 186 of file MailDB.cpp.

References codelog, mailStatusMaskRead, and sDatabase.

187 {
188  DBerror err;
189 
190  if (!sDatabase.RunQuery(err,
191  " UPDATE mailMessage "
192  " SET statusMask = statusMask & ~%u "
193  " WHERE toCharacterIDs LIKE '%%%u%%'" , mailStatusMaskRead, characterID)) {
194  codelog(DATABASE__ERROR, " Failed to mark all as read" );
195  return;
196  }
197 }
#define sDatabase
Definition: dbcore.h:199
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39
void MailDB::MarkAllAsUnreadByLabel ( uint32  characterID,
int  labelID 
)

Definition at line 213 of file MailDB.cpp.

References BitFromLabelID(), codelog, and sDatabase.

214 {
215  int bit = BitFromLabelID(labelID);
216  DBerror err;
217 
218  if (!sDatabase.RunQuery(err,
219  " UPDATE mailMessage SET "
220  " statusMask = statusMask & ~%u "
221  " WHERE toCharacterIDs LIKE '%%%u%%' "
222  " AND (labelMask & (1 << %u)) > 0" , characterID, bit))
223  {
224  codelog(DATABASE__ERROR, " Failed to mark all as read by label" );
225  return;
226  }
227 }
#define sDatabase
Definition: dbcore.h:199
static int BitFromLabelID(int id)
Definition: MailDB.cpp:595
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39

Here is the call graph for this function:

void MailDB::MoveAllFromTrash ( uint32  characterID)

Definition at line 397 of file MailDB.cpp.

References codelog, mailStatusMaskTrashed, and sDatabase.

398 {
399  DBerror err;
400  if (!sDatabase.RunQuery(err,
401  " UPDATE mailMessage "
402  " WHERE senderID = %u "
403  " SET statusMask = statusMask | %u" , characterID, mailStatusMaskTrashed)) {
404  codelog(DATABASE__ERROR, " Failed to move all from trash" );
405  }
406 }
#define sDatabase
Definition: dbcore.h:199
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39
void MailDB::MoveAllToTrash ( uint32  characterID)

Definition at line 408 of file MailDB.cpp.

References codelog, mailStatusMaskTrashed, and sDatabase.

409 {
410  DBerror err;
411  if (!sDatabase.RunQuery(err,
412  " UPDATE mailMessage "
413  " WHERE characterID LIKE '%%%u%%' "
414  " SET statusMask = statusMask & ~%u" , characterID, mailStatusMaskTrashed)) {
415  codelog(DATABASE__ERROR, " Failed to move message to trash" );
416  }
417 }
#define sDatabase
Definition: dbcore.h:199
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39
void MailDB::MoveFromTrash ( int32  messageID)

Definition at line 793 of file MailDB.cpp.

794 {
795 
796 }
void MailDB::MoveToTrash ( int32  messageID)

Definition at line 419 of file MailDB.cpp.

References codelog, mailStatusMaskTrashed, and sDatabase.

420 {
421  DBerror err;
422 
423  if (!sDatabase.RunQuery(err,
424  " UPDATE mailMessage "
425  " WHERE messageID = %u "
426  " SET statusMask = statusMask | %u" , messageID, mailStatusMaskTrashed)) {
427  codelog(DATABASE__ERROR, " Failed to move message to trash" );
428  }
429 
430 }
#define sDatabase
Definition: dbcore.h:199
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39
void MailDB::MoveToTrashByLabel ( int32  characterID,
int32  labelID 
)

Definition at line 432 of file MailDB.cpp.

References BitFromLabelID(), codelog, and sDatabase.

433 {
434  int bit = BitFromLabelID(labelID);
435 
436  DBerror err;
437 
438  if (!sDatabase.RunQuery(err,
439  " UPDATE mailMessage "
440  " SET labelMask = -1 "
441  " WHERE toCharacterIDs LIKE '%%%u%%' "
442  " AND (labelMask & (1 << %u)) > 0" , characterID, bit))
443  {
444  codelog(DATABASE__ERROR, " Failed to move message to trash by label" );
445  }
446 }
#define sDatabase
Definition: dbcore.h:199
static int BitFromLabelID(int id)
Definition: MailDB.cpp:595
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39

Here is the call graph for this function:

void MailDB::RemoveLabelMask ( int32  messageID,
int  mask 
)

Definition at line 528 of file MailDB.cpp.

References codelog, and sDatabase.

529 {
530  DBerror err;
531  if (!sDatabase.RunQuery(err,
532  " UPDATE mailStatus "
533  " SET labelMask = (labelMask & ~%u) "
534  " WHERE messageID = %u;" , mask, messageID))
535  {
536  codelog(DATABASE__ERROR, " Failed to apply label mask to message" );
537  }
538 }
#define sDatabase
Definition: dbcore.h:199
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39
void MailDB::RemoveLabelMasks ( std::vector< int32 messageIDs,
int  mask 
)

Definition at line 567 of file MailDB.cpp.

References _log, DBerror::c_str(), codelog, and sDatabase.

568 {
569  DBerror err;
570 
571  if (messageIDs.size() == 0) {
572  return;
573  }
574 
575  std::ostringstream query;
576  query << " UPDATE mailStatus SET labelMask = labelMask & ~" << mask << " " ;
577 
578  query << " WHERE messageID = " << messageIDs[0];
579 
580  for (int i = 1; i < messageIDs.size(); i++) {
581  query << " OR messageID = " << messageIDs[i];
582  }
583 
584  _log(DATABASE__ERROR, query.str().c_str());
585 
586 
587  if (!sDatabase.RunQuery(err, query.str().c_str()))
588  {
589  codelog(DATABASE__ERROR, " Failed to apply labels" );
590  return;
591  }
592 }
#define sDatabase
Definition: dbcore.h:199
#define _log(type, fmt,...)
Definition: logsys.h:124
const char * c_str() const
Definition: dbcore.h:48
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39

Here is the call graph for this function:

void MailDB::RemoveLabels ( std::vector< int32 messageIDs,
int  labelID 
)

Definition at line 246 of file MailDB.cpp.

References _log, BitFromLabelID(), DBerror::c_str(), codelog, and sDatabase.

247 {
248  DBerror err;
249 
250  if (messageIDs.size() == 0) {
251  return;
252  }
253 
254  int bit = BitFromLabelID(labelID);
255  std::ostringstream query;
256  query << " UPDATE mailMessage SET labelMask = labelMask & ~(1 << " << bit << " ) " ;
257 
258  query << " WHERE (labelMask & (1 << " << bit << " )) > 0 AND (" ;
259  query << " messageID = " << messageIDs[0];
260 
261  for (int i = 1; i < messageIDs.size(); i++) {
262  query << " OR messageID = " << messageIDs[i];
263  }
264 
265  query << " )" ;
266  _log(DATABASE__ERROR, query.str().c_str());
267 
268 
269  if (!sDatabase.RunQuery(err, query.str().c_str()))
270  {
271  codelog(DATABASE__ERROR, " Failed to delete labels" );
272  return;
273  }
274 }
#define sDatabase
Definition: dbcore.h:199
#define _log(type, fmt,...)
Definition: logsys.h:124
static int BitFromLabelID(int id)
Definition: MailDB.cpp:595
const char * c_str() const
Definition: dbcore.h:48
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39

Here is the call graph for this function:

void MailDB::RemoveStatusMask ( int32  messageID,
int  mask 
)

Definition at line 502 of file MailDB.cpp.

References codelog, and sDatabase.

Referenced by SetMailUnread().

503 {
504  DBerror err;
505  if (!sDatabase.RunQuery(err,
506  " UPDATE mailStatus "
507  " SET statusMask = statusMask & ~%u "
508  " WHERE messageID = %u" , mask, messageID)) {
509  codelog(DATABASE__ERROR, " Failed to remove status mask" );
510  }
511 }
#define sDatabase
Definition: dbcore.h:199
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39

Here is the caller graph for this function:

void MailDB::RemoveStatusMasks ( std::vector< int32 messageIDs,
int  mask 
)

Definition at line 469 of file MailDB.cpp.

References DBerror::c_str(), codelog, and sDatabase.

Referenced by SetMailsUnread().

470 {
471  if (messageIDs.size() == 0) {
472  return;
473  }
474 
475  std::ostringstream query;
476 
477  query << " UPDATE mailStatus SET statusMask = statusMask & ~" << mask << " WHERE " ;
478  query << " messageID = " << messageIDs[0];
479  for (int i = 1; i < messageIDs.size(); i++) {
480  query << " OR messageID = " << messageIDs[i];
481  }
482 
483  DBerror err;
484 
485  if (!sDatabase.RunQuery(err, query.str().c_str())) {
486  codelog(DATABASE__ERROR, " Failed to remove status mask" );
487  }
488 }
#define sDatabase
Definition: dbcore.h:199
const char * c_str() const
Definition: dbcore.h:48
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39

Here is the call graph for this function:

Here is the caller graph for this function:

int MailDB::SendMail ( int  sender,
std::vector< int > &  toCharacterIDs,
int  toListID,
int  toCorpOrAllianceID,
std::string &  title,
std::string &  body,
int  isReplyTo,
int  isForwardedFrom 
)

Definition at line 59 of file MailDB.cpp.

References Buffer::begin(), codelog, DeflateData(), Buffer::end(), DBResultRow::GetInt(), DBQueryResult::GetRow(), mailLabelInbox, PRIu64, sDatabase, and Win32TimeNow().

60 {
61  // build a string with ',' seperated char ids
62  std::string toStr;
63  for (size_t i = 0; i < toCharacterIDs.size(); i++)
64  {
65  toStr += std::to_string(toCharacterIDs[i]);
66  // only add ',' when this isn't the last ID
67  if (i != (toCharacterIDs.size() - 1))
68  toStr += " ," ;
69  }
70 
71  // sanitize these ids
72  if (toListID == -1)
73  toListID = 0;
74  if (toCorpOrAllianceID == -1)
75  toCorpOrAllianceID = 0;
76 
77  // compress the body
78  Buffer bodyCompressed;
79  Buffer bodyInput(body.begin(), body.end());
80  DeflateData(bodyInput, bodyCompressed);
81 
82  // ugh - buffer doesn't give us the actual buffer.. what the?
83  std::string bodyCompressedStr(bodyCompressed.begin<char>(), bodyCompressed.end<char>());
84 
85  // escape it to not break the query with special characters
86  std::string bodyEscaped;
87  sDatabase.DoEscapeString(bodyEscaped, bodyCompressedStr);
88 
89  // default label is 1 = Inbox
90  const int defaultLabel = 1;
91 
92  // TODO(groove): Maybe do checks to see if we're allowed to send mails to
93  // whereever it's going
94  DBerror err;
95  uint32 messageID;
96 
97  if (!sDatabase.RunQueryLID(err, messageID,
98  " INSERT INTO mailMessage "
99  " (senderID, toCharacterIDs, toListID, toCorpOrAllianceID, "
100  " title, body, sentDate) "
101  " VALUES (%u, '%s', %d, %d, '%s', '%s', %" PRIu64 " )" ,
102  sender, toStr.c_str(), toListID, toCorpOrAllianceID, title.c_str(),
103  bodyEscaped.c_str(), Win32TimeNow()));
104  {
105  codelog(DATABASE__ERROR, " Failed to insert mailMessage" );
106  // TODO: Why returning false always?
107  }
108 
109  if (toCharacterIDs.size() > 0) {
110  for (int i = 0; i < toCharacterIDs.size(); i++) {
111  uint32 id = toCharacterIDs[i];
112  if (!sDatabase.RunQuery(err,
113  " INSERT INTO mailStatus "
114  " (messageID, characterID, statusMask, labelMask)"
115  " VALUES (%u, %u, %u, %u)" , messageID, id, 0, mailLabelInbox))
116  {
117  codelog(DATABASE__ERROR, " Failed to insert mailStatus for character ids" );
118  return 0;
119  }
120  }
121  }
122 
123  if (toListID > 0) {
124  DBQueryResult res;
125  if (!sDatabase.RunQuery(res,
126  " SELECT characterID FROM mailListUsers "
127  " WHERE listID = %u" , toListID))
128  {
129  codelog(DATABASE__ERROR, " Failed to get mailing list members" );
130  return 0;
131  }
132  DBResultRow row;
133  while (res.GetRow(row))
134  {
135  uint32 id = row.GetInt(0);
136  if (!sDatabase.RunQuery(err,
137  " INSERT INTO mailStatus "
138  " (messageID, characterID, statusMask, labelMask)"
139  " VALUES (%u, %u, %u, %u)" , messageID, id, 0, mailLabelInbox))
140  {
141  codelog(DATABASE__ERROR, " Failed to insert mailStatus for character ids" );
142  return 0;
143  }
144  }
145  }
146  // TODO(groove) corp/alliance mails
147 
148  return messageID;
149 }
#define sDatabase
Definition: dbcore.h:199
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
iterator< T > begin()
Definition: Buffer.h:381
Generic class for buffers.
Definition: Buffer.h:40
#define codelog(type, fmt,...)
Definition: logsys.h:128
bool DeflateData(Buffer &data)
Deflates given data.
Definition: Deflate.cpp:37
int64 Win32TimeNow()
Definition: utils_time.cpp:70
unsigned __int32 uint32
Definition: eve-compat.h:50
#define PRIu64
Definition: eve-compat.h:85
Definition: dbcore.h:39
iterator< T > end()
Definition: Buffer.h:387

Here is the call graph for this function:

void MailDB::SetMailingListDefaultAccess ( int32  listID,
int32  defaultAccess,
int32  defaultMemberAccess,
int32  cost 
)

Definition at line 759 of file MailDB.cpp.

References codelog, and sDatabase.

760 {
761  DBerror err;
762 
763  if (!sDatabase.RunQuery(err,
764  " UPDATE mailList "
765  " SET defaultAccess = %u, defaultMemberAccess = %u, cost = %u "
766  " WHERE id = %u" , defaultAccess, defaultMemberAccess, cost, listID))
767  {
768  codelog(DATABASE__ERROR, " Failed to update mailing list defaults" );
769  return;
770  }
771 }
#define sDatabase
Definition: dbcore.h:199
#define codelog(type, fmt,...)
Definition: logsys.h:128
Definition: dbcore.h:39
void MailDB::SetMailRead ( int  id)

Definition at line 171 of file MailDB.cpp.

References ApplyStatusMask(), and mailStatusMaskRead.

172 {
174 }
void ApplyStatusMask(int32 messageID, int mask)
Definition: MailDB.cpp:490

Here is the call graph for this function:

void MailDB::SetMailsRead ( std::vector< int32 ids)

Definition at line 181 of file MailDB.cpp.

References ApplyStatusMasks(), and mailStatusMaskRead.

182 {
184 }
void ApplyStatusMasks(std::vector< int32 > messageIDs, int mask)
Definition: MailDB.cpp:448

Here is the call graph for this function:

void MailDB::SetMailsUnread ( std::vector< int32 ids)

Definition at line 176 of file MailDB.cpp.

References mailStatusMaskRead, and RemoveStatusMasks().

177 {
179 }
void RemoveStatusMasks(std::vector< int32 > messageIDs, int mask)
Definition: MailDB.cpp:469

Here is the call graph for this function:

void MailDB::SetMailUnread ( int  id)

Definition at line 166 of file MailDB.cpp.

References mailStatusMaskRead, and RemoveStatusMask().

167 {
169 }
void RemoveStatusMask(int32 messageID, int mask)
Definition: MailDB.cpp:502

Here is the call graph for this function:


The documentation for this class was generated from the following files: