Thread

Index > Scribe > Filtering sent mail by mail.To field
Author/Date Filtering sent mail by mail.To field
Scott
15/11/2017 11:21pm
I'm trying to sort my sent folder by the mail.To field, but I'm having difficulty. Ideally, I'd like to sort by specific emails being present in the mail.To field and then by addressees being in various Contact Groups.

I'm not getting too far. I tried
lst = Mail.To
but I get the error: Unexpected token 'lst' in list definition Any suggestions?
fret
16/11/2017 4:04pm
"Unexpected token 'lst' in list definition"
This error is in response to the compiler trying to generate a list value to assign to a variable. Maybe like:

Var = {45, 93, "asd"};

So maybe you have a syntax error further up in your code? The curly brackets are used for scoping as well. Hard to know without more context.

Speaking of which, sorting by the "To" field is a user interface option, not a scripting thing. So that doesn't make sense to me. Just click the "To" field while in the Sent folder?
Scott
17/11/2017 12:22pm
I'm hoping to sort the Sent folder into different folders within different mail stores.
I've got the lst portion working.

How do I access the contents of a contact group? I want to loop through the To addressees and sort it into the folder of the contact group.
fret
17/11/2017 2:00pm
function ListGroup(App, Thing, Menu)
{
	if (Thing.Type != 0xaaff0001)
	{
		Print("Error: Not an email.\n");
		return false;
	}
	
	for (i=0; i<Thing.To.Length; i++)
	{
		Recip = Thing.To[ i];
		e = Recip.Email;
		grps = Recip.Groups;
		if (grps)
		{
			Print("Recip["+i+"]: "+e+" is in "+grps+"\n");
			for (n=0; n<grps.Length(); n++)
			{
				grp = App.LookupContactGroup(grps[n]);
				for (k=0; k<grp.List.Length; k++)
					Print("\tGrp has: "+grp.List[k]+"\n");
			}
		}
	}
	
	return true;
}

function Main(App)
{
	if (!AddCallback("OnThingContextMenu", "ListGroup"))
		MsgBox(App, "Couldn't add ListGroup");

	return 1;
}
Except that 'LookupContactGroup' doesn't exist yet. I'll add it to the next build. Or you could write your own, that gets the contact folder and iterates over it and finds the right group. Or better yet, make a hash table first and then use that to look up groups.
Scott
26/11/2017 4:02am
This works fairly well except for the following error:
Grp has: (null)
ListContacts.script:13 IDomGet warning: Unexpected Dom member 'Groups'.

The last line appears several times in each instance.
I am unable to get rid of this error.

A minor note, the "less than" symbol needed to be translated.
fret
26/11/2017 8:50am
To get rid of that error you can put an "if (grp)" test after the lookup.
Scott
26/11/2017 9:50am
It seems that the error is generated by the line:
grps = Recip.Groups;
I put Print statments around each line. This is also the line referred to by the line number in the error message.
It looks attempting to access the Groups member generates the error. Checking for null afterwards is too late; the message has been printed.
fret
05/12/2017 11:35pm
It seems that the error is generated by the line:
grps = Recip.Groups;

Yes, the get variant handler for the store3 address "group" field was returning false when it didn't have to. So I fixed that for the next release.
Scott
12/01/2018 10:52am
I think this portion of your sample code reveals a bug in the code:
grp = App.LookupContactGroup(grps[n]);
for (k=0; k<grp.List.Length; k++)
    Print("\tGrp has: "+grp.List[k]+"\n");


The variable grp.List.Length contains the length in characters of the group. Shouldn't it return the number of elements in the list?

As the code is now, I have to check for null before printing the group contents, otherwise, I get a whack of nulls printed.
Reply