API Wont let me get message by db id

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
Baaleos
New user
New user
Posts: 7
Joined: 2019-05-13 14:38

API Wont let me get message by db id

Post by Baaleos » 2020-11-11 17:00

Code: Select all

var spams = GetMessagesFromList();

                foreach(long l in spams)
                {
                    try
                    {
                        Console.WriteLine("Processing Spam:" + l);
                        var msg = inboxFolder.Messages.ItemByDBID[l];
                        var theMessage = new Message(msg);
                        messages.Add(theMessage);
                    }
                    catch (Exception e) {
                        Console.WriteLine(e.ToString());
                    }
                }
I am using C#
the spams list in this test is just reading from a text file that contains a single number..
I am setting this number manually to test -
This is a db item I am trying to target:
I have tried specifying both 815980 and 4126:
To match this row in the db
messageid messageaccountid messagefolderid messagefilename messagetype messagefrom messagesize messagecurnooftries messagenexttrytime messageflags messagecreatetime messagelocked messageuid
815980 4006 12039 {1148D25C-29A1-4938-988D-960CC282E93B}.eml 2 *****@0337.com 3228 0 1901-01-01 00:00:00.000 32 2020-11-09 08:44:38.000 0 4126

But no matter which one I specify to the inboxFolder.Messages.ItemByDBID[l]; object, I receive 'Invalid Index' COM Exception.

I have also tried inboxFolder.Messages[] specifying the l variable in there...
That also throws an Invalid Index exception.


The only way I have of accessing messages is to loop from 0 - > Count-1 of messages and grab them one by one.

Any idea whats going on here?

Baaleos
New user
New user
Posts: 7
Joined: 2019-05-13 14:38

Re: API Wont let me get message by db id

Post by Baaleos » 2020-11-11 17:11

When testing with another email - it appears to work.
But I have a few hundred- possibly thousands where I am unable to grab the message by its dbid directly.

Does the API require the message be indexed etc?
I imported these messages from an external account - and there is over 30k of them.
I turned indexing off - just wondering if I need that on.


The message that the API wont grab definitely exists in the db and on the disk - I went and found it in the data directory in a sub directory named 86 etc - which I guess is just named after the first 2 digits of the guid used for the message itself.

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

Re: API Wont let me get message by db id

Post by mattg » 2020-11-11 23:00

When are you trying to grab the DBID?
I think it changes once during incoming delivery
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

Baaleos
New user
New user
Posts: 7
Joined: 2019-05-13 14:38

Re: API Wont let me get message by db id

Post by Baaleos » 2020-11-12 13:15

In my case- these are emails that are static and not in flight.
Eg: they arrived a day or two ago - and I am just grabbing them via the interop api.

My setup:

hmailserver- (hosted on a machine called beta.com or something like that)
Domain - (this is actually a domain hosted elsewhere: lets call it alpha.com)
account - this account is called baaleos@alpha.com or something like that

The account is configured to use an external account to download via pop protocol the 40k of emails from alpha.com

This succeeds -
However when I try to access the emails directly via scripting API
Like this:

private static Message GetSingleMessage(string account, string box, long id)
{
Domain domain = _app.Domains.ItemByName["alpha.com"];
Account dAccount = domain.Accounts.ItemByAddress[account];
IMAPFolder inboxFolder = dAccount.IMAPFolders.ItemByName[box];


var msg = inboxFolder.Messages.ItemByDBID[id];
return new Message(msg);

}

In my first post I showed the db extract for a message in the hmail db:

815980 is the messageid
4126 is the messageuid

I have tried both numbers above - and it returns 'index is invalid'
Its almost like ItemByDBID only picks up items loaded within a certain range of a cursor or something?


Update:
Something even weirder is happening now...
My Hmail account was left downloading 40k of messages, it finished, I was able to see them on my iPhone and everything...
Now this morning, after a server reboot - I refresh my iphone and the messages are gone.

When I check on hmailadmin - I can see that the account still has 1gb of messages present under it - but they are not being sent to my mail client.
The following error is shown in the logs

"ERROR" 5800 "2020-11-12 10:46:39.339" "Severity: 2 (High), Code: HM5033, Source: DALRecordset::Open, Description: Source: ADOConnection::Execute, Code: HM10046, Description: Unknown error when executing SQL statement.
select * from hm_messages where messageaccountid = ? and messagefolderid = ? order by messageuid asc
Microsoft OLE DB Provider for SQL Server
Query timeout expired"
"ERROR" 1108 "2020-11-12 11:11:15.282" "Severity: 2 (High), Code: HM5033, Source: DALRecordset::Open, Description: Source: ADOConnection::Execute, Code: HM10046, Description: Unknown error when executing SQL statement.
select * from hm_messages where messageaccountid = ? and messagefolderid = ? order by messageuid asc
Microsoft OLE DB Provider for SQL Server
Query timeout expired"

Baaleos
New user
New user
Posts: 7
Joined: 2019-05-13 14:38

Re: API Wont let me get message by db id

Post by Baaleos » 2020-11-12 13:25

The HMailServer Process seems to be spinning around 87% etc
Odd


The mails have reappeared in my iphone - I suspect when the process gets threadlocked - it shows the inbox as empty.

Post Reply