summaryrefslogtreecommitdiff
path: root/spamfilter/spamcheckdata.c
diff options
context:
space:
mode:
Diffstat (limited to 'spamfilter/spamcheckdata.c')
-rw-r--r--spamfilter/spamcheckdata.c273
1 files changed, 273 insertions, 0 deletions
diff --git a/spamfilter/spamcheckdata.c b/spamfilter/spamcheckdata.c
new file mode 100644
index 0000000..5e27150
--- /dev/null
+++ b/spamfilter/spamcheckdata.c
@@ -0,0 +1,273 @@
+/*
+
+"Spam Filter"-Plugin for Miranda IM
+
+Copyright 2003-2006 Heiko Herkenrath
+
+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 (at your option) 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 ("SpamFilter-License.txt"); if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+
+// -- Includes
+#include "common.h"
+
+
+// -----------------------------------------
+
+
+
+WCHAR* SCD_DecodeUserName(SPAMCHECKDATA* pscd)
+{
+ if (pscd->dwFlags & SCDF_NO_CONTACT)
+ {
+ #if defined(UNICODE)
+ if (pscd->dwFlags&SCDF_UNICODE)
+ return mir_wstrdup(pscd->pwszUserName);
+ else
+ return (WCHAR*)mir_utf8encodeW((WCHAR*)pscd->pszUserName);
+ #else
+ if (pscd->dwFlags&SCDF_UNICODE)
+ return UnicodeToAnsi(pscd->pwszUserName);
+ else
+ return mir_strdup(pscd->pszUserName);
+ #endif
+
+ } else {
+ return NULL;
+ }
+}
+
+
+BOOL SCD_IsUserValid(SPAMCHECKDATA* pscd)
+{
+ if (pscd->dwFlags&SCDF_NO_CONTACT)
+ return (pscd->ptszUserName ? TRUE : FALSE);
+ else
+ return (pscd->hContact && (pscd->hContact != INVALID_HANDLE_VALUE));
+}
+
+
+
+WCHAR* SCD_GetContactCustomDisplayName(SPAMCHECKDATA* pscd)
+{
+ // MS_CLIST_GETCONTACTDISPLAYNAME caches it's internal calls to
+ // MS_CONTACT_GETCONTACTINFO, we use it directly here (avoiding cached data)
+
+ // GCDNF_NOCACHE flag for MS_CLIST_GETCONTACTDISPLAYNAME
+ // could be used, too
+
+ WCHAR* pszReturn;
+
+ // No contact available
+ if (pscd->dwFlags&SCDF_NO_CONTACT)
+ {
+ return SCD_DecodeUserName(pscd);
+
+
+ // Normal hContact (CList name)
+ } else {
+
+ CONTACTINFO ci;
+
+ ZeroMemory(&ci, sizeof(ci));
+ ci.cbSize = sizeof(ci);
+ ci.hContact = pscd->hContact;
+ #if defined(UNICODE)
+ ci.dwFlag = CNF_DISPLAY|CNF_UNICODE;
+ #else
+ ci.dwFlag = CNF_DISPLAY;
+ #endif
+
+ pszReturn = NULL;
+ if (CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci) == 0)
+ if (ci.type == CNFT_ASCIIZ)
+ if (lstrlen(ci.pszVal) > 0)
+ pszReturn = ci.pszVal; // MS_CONTACT_GETCONTACTINFO uses mir_alloc
+
+ if (!pszReturn)
+ {
+ #if defined(UNICODE)
+ ci.dwFlag = CNF_UNIQUEID|CNF_UNICODE;
+ #else
+ ci.dwFlag = CNF_UNIQUEID;
+ #endif
+
+ if (CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci) == 0)
+ {
+ if (ci.type == CNFT_ASCIIZ) {
+ pszReturn = ci.pszVal; // MS_CONTACT_GETCONTACTINFO uses mir_alloc
+ } else if (ci.type == CNFT_DWORD) {
+ pszReturn = (WCHAR*)mir_alloc((MAX_INT_LENGTH+1)*sizeof(WCHAR));
+ if (pszReturn)
+ mir_sntprintf(pszReturn, (MAX_INT_LENGTH+1), _T("%u"), ci.dVal);
+ } else if (ci.type == CNFT_WORD) {
+ pszReturn = (WCHAR*)mir_alloc((MAX_INT_LENGTH+1)*sizeof(WCHAR));
+ if (pszReturn)
+ mir_sntprintf(pszReturn, (MAX_INT_LENGTH+1), _T("%u"), ci.wVal);
+ } else if (ci.type == CNFT_BYTE) {
+ pszReturn = (WCHAR*)mir_alloc((MAX_INT_LENGTH+1)*sizeof(WCHAR));
+ if (pszReturn)
+ mir_sntprintf(pszReturn, (MAX_INT_LENGTH+1), _T("%u"), ci.bVal);
+ }
+ }
+ }
+
+ }
+
+ return pszReturn;
+}
+
+
+WCHAR* SCD_GetContactName(SPAMCHECKDATA* pscd, BOOL bIncludeUniqueID)
+{
+ // No contact available
+ if (pscd->dwFlags & SCDF_NO_CONTACT)
+ {
+ return SCD_DecodeUserName(pscd);
+
+ // Normal hContact (CList name)
+ } else {
+
+ WCHAR* pszNick;
+ CONTACTINFO ci;
+
+ ZeroMemory(&ci, sizeof(ci));
+ ci.cbSize = sizeof(ci);
+ ci.hContact = pscd->hContact;
+ #if defined(UNICODE)
+ ci.dwFlag = CNF_NICK|CNF_UNICODE;
+ #else
+ ci.dwFlag = CNF_NICK;
+ #endif
+
+ pszNick = NULL;
+ if (CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci) == 0)
+ if (ci.type == CNFT_ASCIIZ)
+ if (lstrlen(ci.pszVal) > 0)
+ pszNick = ci.pszVal; // MS_CONTACT_GETCONTACTINFO uses mir_alloc
+
+ // Append unique id (if whished) or if nick is not available
+ if (bIncludeUniqueID || !pszNick)
+ {
+ WCHAR* pszUniqueID = NULL;
+
+ #if defined(UNICODE)
+ ci.dwFlag = CNF_UNIQUEID|CNF_UNICODE;
+ #else
+ ci.dwFlag = CNF_UNIQUEID;
+ #endif
+
+ if (CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci) == 0)
+ {
+ if (ci.type == CNFT_ASCIIZ) {
+ pszUniqueID = ci.pszVal; // MS_CONTACT_GETCONTACTINFO uses mir_alloc
+ } else if (ci.type == CNFT_DWORD) {
+ pszUniqueID = (WCHAR*)mir_alloc((MAX_INT_LENGTH+1)*sizeof(WCHAR));
+ if (pszUniqueID)
+ mir_sntprintf(pszUniqueID, (MAX_INT_LENGTH+1), _T("%u"), ci.dVal);
+ } else if (ci.type == CNFT_WORD) {
+ pszUniqueID = (WCHAR*)mir_alloc((MAX_INT_LENGTH+1)*sizeof(WCHAR));
+ if (pszUniqueID)
+ mir_sntprintf(pszUniqueID, (MAX_INT_LENGTH+1), _T("%u"), ci.wVal);
+ } else if (ci.type == CNFT_BYTE) {
+ pszUniqueID = (WCHAR*)mir_alloc((MAX_INT_LENGTH+1)*sizeof(WCHAR));
+ if (pszUniqueID)
+ mir_sntprintf(pszUniqueID, (MAX_INT_LENGTH+1), _T("%u"), ci.bVal);
+ }
+ }
+
+ if (!pszNick) {
+ return pszUniqueID;
+
+ } else if (!pszUniqueID) {
+ return pszNick;
+
+ } else {
+
+ int iSize;
+ WCHAR* pszReturn;
+ WCHAR* pszFmt = TranslateT("%s (%s)");
+
+ iSize = (lstrlen(pszFmt) + lstrlen(pszNick) + lstrlen(pszUniqueID) + 1);
+
+ pszReturn = (WCHAR*)mir_alloc(iSize*sizeof(WCHAR));
+ if (!pszReturn) return pszNick;
+
+ mir_sntprintf(pszReturn, iSize, pszFmt, pszNick, pszUniqueID);
+
+ mir_free(pszUniqueID);
+ mir_free(pszNick);
+ return pszReturn;
+ }
+
+ } else {
+ return pszNick;
+ }
+
+ }
+}
+
+
+WCHAR* SCD_GetContactUniqueStr(SPAMCHECKDATA* pscd, BOOL bUseNick)
+{
+ // No contact available
+ if (pscd->dwFlags & SCDF_NO_CONTACT)
+ {
+ return SCD_DecodeUserName(pscd);
+
+
+ // Normal hContact (CList name)
+ } else {
+
+ CONTACTINFO ci;
+ WCHAR* pszReturn;
+
+ ZeroMemory(&ci, sizeof(ci));
+ ci.cbSize = sizeof(ci);
+ ci.hContact = pscd->hContact;
+ #if defined(UNICODE)
+ if (bUseNick)
+ ci.dwFlag = CNF_NICK|CNF_UNICODE;
+ else
+ ci.dwFlag = CNF_UNIQUEID|CNF_UNICODE;
+ #else
+ if (bUseNick)
+ ci.dwFlag = CNF_NICK;
+ else
+ ci.dwFlag = CNF_UNIQUEID;
+ #endif
+
+ pszReturn = NULL;
+ if (CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci) == 0)
+ {
+ if (ci.type == CNFT_ASCIIZ) {
+ pszReturn = (WCHAR*)mir_alloc((lstrlen(ci.pszVal) + lstrlenA(ci.szProto) + 2)*sizeof(WCHAR));
+ mir_sntprintf(pszReturn, (lstrlen(ci.pszVal) + lstrlenA(ci.szProto) + 2), _T("%hs:%s"), ci.szProto ? ci.szProto : "", ci.pszVal);
+ mir_free(ci.pszVal);
+ } else if (ci.type == CNFT_DWORD) {
+ pszReturn = (WCHAR*)mir_alloc((MAX_INT_LENGTH + lstrlenA(ci.szProto) + 2)*sizeof(WCHAR));
+ mir_sntprintf(pszReturn, (MAX_INT_LENGTH + lstrlenA(ci.szProto) + 2), _T("%hs:%u"), ci.szProto ? ci.szProto : "", ci.dVal);
+ } else if (ci.type == CNFT_WORD) {
+ pszReturn = (WCHAR*)mir_alloc((MAX_INT_LENGTH + lstrlenA(ci.szProto) + 2)*sizeof(WCHAR));
+ mir_sntprintf(pszReturn, (MAX_INT_LENGTH + lstrlenA(ci.szProto) + 2), _T("%hs:%u"), ci.szProto ? ci.szProto : "", ci.wVal);
+ } else if (ci.type == CNFT_BYTE) {
+ pszReturn = (WCHAR*)mir_alloc((MAX_INT_LENGTH + lstrlenA(ci.szProto) + 2)*sizeof(WCHAR));
+ mir_sntprintf(pszReturn, (MAX_INT_LENGTH + lstrlenA(ci.szProto) + 2), _T("%hs:%u"), ci.szProto ? ci.szProto : "", ci.bVal);
+ }
+ }
+
+ return pszReturn;
+ }
+} \ No newline at end of file