EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MailDB.cpp
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: caytchen, groove
24 */
25 
26 // @TODO(groove) check characterIDs while doing moves to prevent
27 // client trickery
28 #include "eve-server.h"
29 
30 #include "mail/MailDB.h"
31 #include "EVE_Mail.h"
32 
33 
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 }
46 
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 }
58 
59 int MailDB::SendMail(int sender, std::vector<int>& toCharacterIDs, int toListID, int toCorpOrAllianceID, std::string& title, std::string& body, int isReplyTo, int isForwardedFrom)
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 }
150 
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 }
165 
167 {
169 }
170 
172 {
174 }
175 
176 void MailDB::SetMailsUnread(std::vector<int32> ids)
177 {
179 }
180 
181 void MailDB::SetMailsRead(std::vector<int32> ids)
182 {
184 }
185 
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 }
198 
199 
200 void MailDB::MarkAllAsRead(uint32 characterID)
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 }
212 
213 void MailDB::MarkAllAsUnreadByLabel(uint32 characterID, int labelID)
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 }
228 
229 
230 void MailDB::MarkAllAsReadByLabel(uint32 characterID, int labelID)
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 }
245 
246 void MailDB::RemoveLabels(std::vector<int32> messageIDs, int labelID)
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 }
275 
276 void MailDB::ApplyLabels(std::vector<int32> messageIDs, int labelID)
277 {
278  int bit = BitFromLabelID(labelID);
279  ApplyLabelMasks(messageIDs, (1 << bit));
280 }
281 
282 PyRep* MailDB::GetLabels(int characterID) const
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 }
303 
304 bool MailDB::CreateLabel(int characterID, Call_CreateLabel& args, uint32& newID) const
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 }
334 
335 void MailDB::DeleteLabel(int characterID, int labelID) const
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 }
353 
354 void MailDB::EditLabel(int characterID, Call_EditLabel& args) const
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 }
367 
368 void MailDB::ApplyLabel(int32 messageID, int labelID)
369 {
370  int bit = BitFromLabelID(labelID);
371  ApplyLabelMask(messageID, (1 << bit));
372 }
373 
374 void MailDB::DeleteMail(int32 messageID)
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 }
385 
386 void MailDB::EmptyTrash(uint32 characterID)
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 }
396 
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 }
407 
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 }
418 
419 void MailDB::MoveToTrash(int32 messageID)
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 }
431 
432 void MailDB::MoveToTrashByLabel(int32 characterID, int32 labelID)
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 }
447 
448 void MailDB::ApplyStatusMasks(std::vector<int32> messageIDs, int mask)
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 }
468 
469 void MailDB::RemoveStatusMasks(std::vector<int32> messageIDs, int mask)
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 }
489 
490 void MailDB::ApplyStatusMask(int32 messageID, int mask)
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 }
500 
501 
502 void MailDB::RemoveStatusMask(int32 messageID, int mask)
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 }
512 
513 
514 void MailDB::ApplyLabelMask(int32 messageID, int mask)
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 }
527 
528 void MailDB::RemoveLabelMask(int32 messageID, int mask)
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 }
539 
540 void MailDB::ApplyLabelMasks(std::vector<int32> messageIDs, int mask)
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 }
566 
567 void MailDB::RemoveLabelMasks(std::vector<int32> messageIDs, int mask)
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 }
593 
594 
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 }
606 
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 }
657 
658 
659 uint32 MailDB::CreateMailingList(uint32 creator, std::string name, int32 defaultAccess, int32 defaultMemberAccess, int32 cost)
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 }
687 
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 }
708 
709 
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 }
757 
758 
759 void MailDB::SetMailingListDefaultAccess(int32 listID, int32 defaultAccess, int32 defaultMemberAccess, int32 cost)
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 }
772 
773 void MailDB::DeleteMailingList(uint32 characterID, int32 listID)
774 {
775 
776 }
777 void MailDB::JoinMailingList(uint32 characterID, std::string name)
778 {
779 
780 }
781 void MailDB::LeaveMailingList(uint32 characterID, int32 listID)
782 {
783 
784 }
786 {
787 
788 }
790 {
791 
792 }
794 {
795 
796 }
PyRep * GetLabels(int characterID) const
Definition: MailDB.cpp:282
void DeleteMail(int32 messageID)
Definition: MailDB.cpp:374
Base Python wire object.
Definition: PyRep.h:66
void MarkAllAsUnreadByLabel(uint32 characterID, int labelID)
Definition: MailDB.cpp:213
void DeleteLabel(int characterID, int labelID) const
Definition: MailDB.cpp:335
#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
#define _log(type, fmt,...)
Definition: logsys.h:124
PyObjectEx * DBResultToCRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:402
Python string.
Definition: PyRep.h:430
#define mailingListMemberMuted
Definition: EVE_Mail.h:26
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
void MoveToTrashByLabel(int32 characterID, int32 labelID)
Definition: MailDB.cpp:432
Python's dictionary.
Definition: PyRep.h:719
void EditLabel(int characterID, Call_EditLabel &args) const
Definition: MailDB.cpp:354
void MoveAllToTrash(uint32 characterID)
Definition: MailDB.cpp:408
void SetMailingListDefaultAccess(int32 listID, int32 defaultAccess, int32 defaultMemberAccess, int32 cost)
Definition: MailDB.cpp:759
void RemoveLabelMask(int32 messageID, int mask)
Definition: MailDB.cpp:528
static int BitFromLabelID(int id)
Definition: MailDB.cpp:595
PyDict * GetJoinedMailingLists(uint32 characterID)
Definition: MailDB.cpp:607
void ApplyLabelMasks(std::vector< int32 > messageIDs, int mask)
Definition: MailDB.cpp:540
void DeleteMailingList(uint32 characterID, int32 listID)
Definition: MailDB.cpp:773
void RemoveStatusMask(int32 messageID, int mask)
Definition: MailDB.cpp:502
#define mailingListMemberOwner
Definition: EVE_Mail.h:29
void ApplyStatusMask(int32 messageID, int mask)
Definition: MailDB.cpp:490
void RemoveStatusMasks(std::vector< int32 > messageIDs, int mask)
Definition: MailDB.cpp:469
void SetMailUnread(int id)
Definition: MailDB.cpp:166
signed __int32 int32
Definition: eve-compat.h:49
* args
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
Python boolean.
Definition: PyRep.h:323
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
void MarkAllAsReadByLabel(uint32 characterID, int labelID)
Definition: MailDB.cpp:230
iterator< T > begin()
Definition: Buffer.h:381
Generic class for buffers.
Definition: Buffer.h:40
const char * c_str() const
Definition: dbcore.h:48
Python object.
Definition: PyRep.h:826
void LeaveMailingList(uint32 characterID, int32 listID)
Definition: MailDB.cpp:781
#define codelog(type, fmt,...)
Definition: logsys.h:128
void EmptyTrash(uint32 characterID)
Definition: MailDB.cpp:386
bool DeflateData(Buffer &data)
Deflates given data.
Definition: Deflate.cpp:37
PyDict * GetMailingListMembers(int32 listID)
Definition: MailDB.cpp:688
void MoveToTrash(int32 messageID)
Definition: MailDB.cpp:419
#define mailingListMemberOperator
Definition: EVE_Mail.h:28
void ApplyLabel(int32 messageID, int labelID)
Definition: MailDB.cpp:368
Python integer.
Definition: PyRep.h:231
void MarkAllAsRead(uint32 characterID)
Definition: MailDB.cpp:200
uint32 CreateMailingList(uint32 creator, std::string name, int32 defaultAccess, int32 defaultMemberAccess, int32 cost)
Definition: MailDB.cpp:659
void ApplyLabels(std::vector< int32 > messageIDs, int labelID)
Definition: MailDB.cpp:276
void MarkAllAsUnread(uint32 characterID)
Definition: MailDB.cpp:186
void SetMailRead(int id)
Definition: MailDB.cpp:171
bool IsNull(uint32 index) const
Definition: dbcore.h:102
int64 Win32TimeNow()
Definition: utils_time.cpp:70
int SendMail(int sender, std::vector< int > &toCharacterIDs, int toListID, int toCorpOrAllianceID, std::string &title, std::string &body, int isReplyTo, int isForwardedFrom)
Definition: MailDB.cpp:59
void MailingListSetEntityAccess(int32 entity, int32 access, int32 listID)
Definition: MailDB.cpp:789
unsigned __int32 uint32
Definition: eve-compat.h:50
void ApplyLabelMask(int32 messageID, int mask)
Definition: MailDB.cpp:514
PyRep * GetNewMail(int charId)
Definition: MailDB.cpp:47
#define PRIu64
Definition: eve-compat.h:85
PyString * GetMailBody(int id) const
Definition: MailDB.cpp:151
void MoveFromTrash(int32 messageID)
Definition: MailDB.cpp:793
PyRep * GetMailStatus(int charId)
Definition: MailDB.cpp:34
PyObject * MailingListGetSettings(int32 listID)
Definition: MailDB.cpp:710
void SetMailsRead(std::vector< int32 > ids)
Definition: MailDB.cpp:181
void MailingListClearEntityAccess(int32 entity, int32 listID)
Definition: MailDB.cpp:785
void JoinMailingList(uint32 characterID, std::string name)
Definition: MailDB.cpp:777
size_t GetRowCount()
Definition: dbcore.h:72
bool CreateLabel(int characterID, Call_CreateLabel &args, uint32 &newID) const
Definition: MailDB.cpp:304
#define mailingListAllowed
Definition: EVE_Mail.h:25
void RemoveLabelMasks(std::vector< int32 > messageIDs, int mask)
Definition: MailDB.cpp:567
void SetItem(PyRep *key, PyRep *value)
SetItem adds or sets a database entry.
Definition: PyRep.cpp:713
void RemoveLabels(std::vector< int32 > messageIDs, int labelID)
Definition: MailDB.cpp:246
Definition: dbcore.h:39
void ApplyStatusMasks(std::vector< int32 > messageIDs, int mask)
Definition: MailDB.cpp:448
iterator< T > end()
Definition: Buffer.h:387
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812
void SetMailsUnread(std::vector< int32 > ids)
Definition: MailDB.cpp:176
void MoveAllFromTrash(uint32 characterID)
Definition: MailDB.cpp:397