Session number as object?

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
palinka
Senior user
Senior user
Posts: 1921
Joined: 2017-09-12 17:57

Session number as object?

Post by palinka » 2020-01-18 18:44

Is it possible to extract the session number for use in a script?

User avatar
jimimaseye
Moderator
Moderator
Posts: 8531
Joined: 2011-09-08 17:48

Re: Session number as object?

Post by jimimaseye » 2020-01-18 19:05

I don't believe so. It's not an object as such and therefore not able to use or define.

[Entered by mobile. Excuse my spelling.]
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

User avatar
SorenR
Senior user
Senior user
Posts: 3564
Joined: 2006-08-21 15:38
Location: Denmark

Re: Session number as object?

Post by SorenR » 2020-01-18 19:05

palinka wrote:
2020-01-18 18:44
Is it possible to extract the session number for use in a script?
Yes... Doing it... :mrgreen:

I'll have look this weekend to extract the code changes from my 5.6.8-22 code.

And it's "Thread ID" not session... :wink:

My custom logfiles use it and have been doing so for a while... First column... Corresponds to first column in hMailServer_yyyy_mm_dd.log file.

Code: Select all

3448		"2020-01-01 00:07:33.277"	"--- Connect ---	220.201.84.7    	25"
3448		"2020-01-01 00:07:33.277"	"IDS Add        	220.201.84.7"
3948		"2020-01-01 00:08:10.072"	"IDS Delete     	220.201.84.7"
3948		"2020-01-01 00:08:10.088"	"SPAM/RBL/URIBL 	220.201.84.7    	   	                	Tagged as Spam by SpamAssassin - (Score: 20)"
3448		"2020-01-01 00:08:27.727"	"--- Connect ---	96.82.74.134    	25 	                	96-82-74-134-static.hfc.comcastbusiness.net"
3448		"2020-01-01 00:08:27.727"	"IDS Add        	96.82.74.134"
3448		"2020-01-01 00:08:27.805"	"SnowShoe       	96.82.74.134"
3448		"2020-01-01 00:08:29.290"	"DISCONNECT     	96.82.74.134"
3448		"2020-01-01 00:08:31.993"	"--- Connect ---	89.28.98.110    	25 	                	89-28-98-110.starnet.md"
3448		"2020-01-01 00:08:31.993"	"IDS Add        	89.28.98.110"
3448		"2020-01-01 00:08:32.056"	"SnowShoe       	89.28.98.110"
3448		"2020-01-01 00:08:33.525"	"DISCONNECT     	89.28.98.110"
3072		"2020-01-01 00:15:52.632"	"--- Connect ---	87.48.20.94     	993	                	87-48-20-94-cable.dk.customer.tdc.net"
3072		"2020-01-01 00:15:52.710"	"... GEOLookup  	87.48.20.94     	   	                	dk"
3072		"2020-01-01 00:15:54.164"	"--- Connect ---	87.48.20.94     	993	                	87-48-20-94-cable.dk.customer.tdc.net"
3072		"2020-01-01 00:15:54.164"	"... GEOLookup  	87.48.20.94     	   	                	dk"
3072		"2020-01-01 00:18:15.220"	"--- Connect ---	144.217.41.237  	25 	                	link18.editions-link.com"
3072		"2020-01-01 00:18:15.220"	"IDS Add        	144.217.41.237"
3072		"2020-01-01 00:18:15.331"	"SnowShoe       	144.217.41.237"
3072		"2020-01-01 00:18:16.814"	"DISCONNECT     	144.217.41.237"
1920		"2020-01-01 00:19:00.375"	"IDS BAN        	144.217.41.237"
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

User avatar
SorenR
Senior user
Senior user
Posts: 3564
Joined: 2006-08-21 15:38
Location: Denmark

Re: Session number as object?

Post by SorenR » 2020-01-18 19:30

This is the code from my 5.4.2. It should not be difficult to move it forward to 5.6.8 (I did it but have not documentet it)

It's available as iThreadID = oApp.Status.ThreadID ...

Code: Select all

diff -bur hmailserver-5.4.2-B1964/hmailserver/source/Server/COM/InterfaceStatus.cpp hmailserver-5.4.2/hmailserver/source/Server/COM/InterfaceStatus.cpp
--- hmailserver-5.4.2-B1964/hmailserver/source/Server/COM/InterfaceStatus.cpp	2014-06-07 10:03:10.000000000 +0200
+++ hmailserver-5.4.2/hmailserver/source/Server/COM/InterfaceStatus.cpp	2019-03-04 14:45:12.484375000 +0100
@@ -125,4 +125,20 @@
    }
 }
 
+STDMETHODIMP 
+InterfaceStatus::get_ThreadID(long *pVal)
+{
+   try
+   {
+      if (!m_pStatus)
+         return GetAccessDenied();
+
+      *pVal = m_pStatus->GetThreadID();
+      return S_OK;
+   }
+   catch (...)
+   {
+      return COMError::GenerateGenericMessage();
+   }
+}
 
diff -bur hmailserver-5.4.2-B1964/hmailserver/source/Server/COM/InterfaceStatus.h hmailserver-5.4.2/hmailserver/source/Server/COM/InterfaceStatus.h
--- hmailserver-5.4.2-B1964/hmailserver/source/Server/COM/InterfaceStatus.h	2014-06-07 10:03:10.000000000 +0200
+++ hmailserver-5.4.2/hmailserver/source/Server/COM/InterfaceStatus.h	2019-03-04 14:45:12.375000000 +0100
@@ -51,6 +51,7 @@
    STDMETHOD(get_RemovedViruses)(/*[out, retval]*/ long *pVal);
    STDMETHOD(get_RemovedSpamMessages)(/*[out, retval]*/ long *pVal);
    STDMETHOD(get_SessionCount)(eSessionType iType, long *pVal);
+   STDMETHOD(get_ThreadID)(/*[out, retval]*/ long *pVal);
 
 private:
 
diff -bur hmailserver-5.4.2-B1964/hmailserver/source/Server/Common/Util/ServerStatus.cpp hmailserver-5.4.2/hmailserver/source/Server/Common/Util/ServerStatus.cpp
--- hmailserver-5.4.2-B1964/hmailserver/source/Server/Common/Util/ServerStatus.cpp	2014-06-07 10:03:10.000000000 +0200
+++ hmailserver-5.4.2/hmailserver/source/Server/Common/Util/ServerStatus.cpp	2019-03-04 14:45:12.625000000 +0100
@@ -158,4 +158,11 @@
    {
       return SessionManager::Instance()->GetNumberOfConnections((SessionType) iSessionType);
    }
+
+   int 
+   ServerStatus::GetThreadID() const
+   {
+      DWORD dwThreadID = GetCurrentThreadId();
+      return dwThreadID;
+   }
 }
diff -bur hmailserver-5.4.2-B1964/hmailserver/source/Server/Common/Util/ServerStatus.h hmailserver-5.4.2/hmailserver/source/Server/Common/Util/ServerStatus.h
--- hmailserver-5.4.2-B1964/hmailserver/source/Server/Common/Util/ServerStatus.h	2014-06-07 10:03:10.000000000 +0200
+++ hmailserver-5.4.2/hmailserver/source/Server/Common/Util/ServerStatus.h	2019-03-04 14:45:12.562500000 +0100
@@ -36,6 +36,8 @@
 
       int GetNumberOfSessions(int iSessionType);
 
+      int GetThreadID() const;
+
    private:
 
       int m_iProcessedMessages;
diff -bur hmailserver-5.4.2-B1964/hmailserver/source/Server/hMailServer/hMailServer.idl hmailserver-5.4.2/hmailserver/source/Server/hMailServer/hMailServer.idl
--- hmailserver-5.4.2-B1964/hmailserver/source/Server/hMailServer/hMailServer.idl	2014-06-07 10:03:10.000000000 +0200
+++ hmailserver-5.4.2/hmailserver/source/Server/hMailServer/hMailServer.idl	2019-03-04 14:45:12.250000000 +0100
@@ -497,6 +497,7 @@
    [propget, id(4), helpstring("Gets the number of removed virues")] HRESULT RemovedViruses([out, retval] long *pVal);
    [propget, id(5), helpstring("Gets the number of detected spam messages")] HRESULT RemovedSpamMessages([out, retval] long *pVal);
    [propget, id(6), helpstring("Gets the current number of sessions")] HRESULT SessionCount([in] eSessionType iType, [out, retval] long *pVal);
+   [propget, id(7), helpstring("Gets the current thread number")] HRESULT ThreadID([out, retval] long *pVal);
 };
 
 [
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

palinka
Senior user
Senior user
Posts: 1921
Joined: 2017-09-12 17:57

Re: Session number as object?

Post by palinka » 2020-01-18 21:27

SorenR wrote:
2020-01-18 19:30
It's available as iThreadID = oApp.Status.ThreadID ...
Is this available to non-custom-compiled hmailserver 5.7.0?

Does ThreadID reset after restart? What I mean is, I need a unique identifier.

Is it directly comparable to session #? Does any thread ID overlap any other session?

Muchas gracias.

User avatar
SorenR
Senior user
Senior user
Posts: 3564
Joined: 2006-08-21 15:38
Location: Denmark

Re: Session number as object?

Post by SorenR » 2020-01-18 23:36

Q: Is this available to non-custom-compiled hmailserver 5.7.0?
A: Nope... It's mine! You are free to use it however.

Q: Does ThreadID reset after restart? What I mean is, I need a unique identifier.
A: Yes but it is not unique.

Q: Is it directly comparable to session #? Does any thread ID overlap any other session?
A1: Where do you find session # ?
A2: Threads are reused from email to email but an active thread is 1 (one) email from start to finish.

If by session # you mean the second column in the log file then a thread can utilize multiple sessions during one conversation. Datatransfer, virus check, spam check all have different session # where normal mail handling is incrementet from conversation to conversation and the remaining are not.
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

palinka
Senior user
Senior user
Posts: 1921
Joined: 2017-09-12 17:57

Re: Session number as object?

Post by palinka » 2020-01-18 23:41

SorenR wrote:
2020-01-18 23:36
A2: Threads are reused from email to email but an active thread is 1 (one) email from start to finish.

If by session # you mean the second column in the log file then a thread can utilize multiple sessions during one conversation. Datatransfer, virus check, spam check all have different session # where normal mail handling is incrementet from conversation to conversation and the remaining are not.
Ah. OK. Well, I had an idea. It's outside my scope of ability. :(

User avatar
SorenR
Senior user
Senior user
Posts: 3564
Joined: 2006-08-21 15:38
Location: Denmark

Re: Session number as object?

Post by SorenR » 2020-01-18 23:47

palinka wrote:
2020-01-18 23:41
SorenR wrote:
2020-01-18 23:36
A2: Threads are reused from email to email but an active thread is 1 (one) email from start to finish.

If by session # you mean the second column in the log file then a thread can utilize multiple sessions during one conversation. Datatransfer, virus check, spam check all have different session # where normal mail handling is incrementet from conversation to conversation and the remaining are not.
Ah. OK. Well, I had an idea. It's outside my scope of ability. :(
Care to share what your idea is about?
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

palinka
Senior user
Senior user
Posts: 1921
Joined: 2017-09-12 17:57

Re: Session number as object?

Post by palinka » 2020-01-18 23:57

SorenR wrote:
2020-01-18 23:47
palinka wrote:
2020-01-18 23:41
SorenR wrote:
2020-01-18 23:36
A2: Threads are reused from email to email but an active thread is 1 (one) email from start to finish.

If by session # you mean the second column in the log file then a thread can utilize multiple sessions during one conversation. Datatransfer, virus check, spam check all have different session # where normal mail handling is incrementet from conversation to conversation and the remaining are not.
Ah. OK. Well, I had an idea. It's outside my scope of ability. :(
Care to share what your idea is about?
In my connection log project, I normally group things by ipaddress. Actually, there's no real grouping, but I setup notifications to myself for various things using the IP as the identifier, which gives me all data for a particular IP, which can span many multiple messages. I wanted to group them by a unique identifier so I could look at per-session or per-message data if I wanted to. The problem is that I gather the data from the various subroutines in eventhandlers.vbs (OnClientConnect, OnHELO, etc). I could easily create a unique identifier within each sub to group multiple entries within that sub (eg: From, To, etc), but I was hoping there was a way to follow the connection through all the subs. That's why session number made sense. It starts before OnClientConnect and remains the same all the way through the time the connection is disconnected.

User avatar
mattg
Moderator
Moderator
Posts: 20792
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Session number as object?

Post by mattg » 2020-01-19 00:56

palinka wrote:
2020-01-18 21:27
What I mean is, I need a unique identifier.
oMessage.id is unique

https://www.hmailserver.com/documentati ... ct_message
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

palinka
Senior user
Senior user
Posts: 1921
Joined: 2017-09-12 17:57

Re: Session number as object?

Post by palinka » 2020-01-19 01:03

mattg wrote:
2020-01-19 00:56
palinka wrote:
2020-01-18 21:27
What I mean is, I need a unique identifier.
oMessage.id is unique

https://www.hmailserver.com/documentati ... ct_message
Yes, but it can't be called at OnClientConnect or OnHELO.

However, I guess it would be possible to move all my IP and HELO related filters from OnHELO to OnAcceptMessage. That would actually simplify a few things as well, but it would also cause every connection to submit DATA and get passed to spamassassin. I'll look into that. This could be a good solution.

User avatar
SorenR
Senior user
Senior user
Posts: 3564
Joined: 2006-08-21 15:38
Location: Denmark

Re: Session number as object?

Post by SorenR » 2020-01-19 01:17

mattg wrote:
2020-01-19 00:56
palinka wrote:
2020-01-18 21:27
What I mean is, I need a unique identifier.
oMessage.id is unique

https://www.hmailserver.com/documentati ... ct_message
Yes but it only exist in oMessage AFTER the message is received.

Hmm... Comparing the logs from 5.4.2 (my initial development for ThreadID) and the logs from 5.6.8 it is clear something has changed. I will need to dig deeper into this as it seems this mod with 5.6.8 is useless... :evil:
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

palinka
Senior user
Senior user
Posts: 1921
Joined: 2017-09-12 17:57

Re: Session number as object?

Post by palinka » 2020-01-19 04:45

mattg wrote:
2020-01-19 00:56
palinka wrote:
2020-01-18 21:27
What I mean is, I need a unique identifier.
oMessage.id is unique

https://www.hmailserver.com/documentati ... ct_message
oMessage.ID called at OnAcceptMessage gives me only "0". I recorded it into the event log to be sure.

EventLog.Write( "oMessage.ID: " & oMessage.ID )

Code: Select all

5968	"2020-01-18 21:38:41.845"	"oMessage.ID: 0"
5968	"2020-01-18 21:44:09.818"	"oMessage.ID: 0"

User avatar
mattg
Moderator
Moderator
Posts: 20792
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Session number as object?

Post by mattg » 2020-01-19 05:41

SorenR wrote:
2020-01-19 01:17
Yes but it only exist in oMessage AFTER the message is received.
I use oMessage.id to create a unique file name when saving attachments (after the message has been accepted)
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

palinka
Senior user
Senior user
Posts: 1921
Joined: 2017-09-12 17:57

Re: Session number as object?

Post by palinka » 2020-01-19 06:29

mattg wrote:
2020-01-19 05:41
SorenR wrote:
2020-01-19 01:17
Yes but it only exist in oMessage AFTER the message is received.
I use oMessage.id to create a unique file name when saving attachments (after the message has been accepted)
The message hasn't been received before OnAcceptMessage? I thought OnSMTPData was when it was received.

Either way, I created my own unique identifier: "SELECT MAX(msgID)+1 AS newmsgid FROM hm_accrej". Actually works great. The table for my connection log was already there. All I added was the msgID column. The whole thing is self contained in one SQL query. :D

User avatar
jimimaseye
Moderator
Moderator
Posts: 8531
Joined: 2011-09-08 17:48

Re: Session number as object?

Post by jimimaseye » 2020-01-19 10:58

palinka wrote:
2020-01-18 18:44
Is it possible to extract the session number for use in a script?
jimimaseye wrote:
2020-01-18 19:05
I don't believe so. It's not an object as such and therefore not able to use or define.
*puffs chest out and looks annoyingly smug* :mrgreen: 🤓
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

Post Reply