Outlook add-in: How to find localized name of the "Junk e-mail"folder

T

tnemec78

Hi,
I am writing an C++COM add-in that will add improved spam filtering. I
have a toolbar with a "Mark as spam" button for this purpose. How do I
find out what is the name of the folder that acts as Junk e-mail
folder. I presume that the actual name and path to this folder can
differ based on the office localization and/or user language settings
and/or account settings ... It might as well be that no such folder
exists and it needs to be created (i.e. in pre-Office 2003 versions)

Please help.

Many thanks
 
K

Ken Slovak - [MVP - Outlook]

NameSpace.GetDefaultFolder(OlDefaultFolders.olFolderJunk) will work for any
Outlook version that has a Junk folder. That's language independent.
 
T

tnemec78

Firstly thank you very much for your quick reply, I really appreciate
it! I found out that this solution is almost there but not quite...

In my environment I have these Outlook folders:
\Personal Folders\
\Personal Folders\Deleted Items
\Personal Folders\Drafts
\Personal Folders\Inbox
\Personal Folders\Junk E-mail
\Personal Folders\Sent Items
....
\Archive Folders
\[email protected]\
\[email protected]\Inbox
\[email protected]\Inbox.Drafts
\[email protected]\Inbox.Sent
\[email protected]\Junk E-mail
....
The latter is my default data file or whatever it is called.
Now Session.GetDefaultFolder(olFolderJunk) points to \Private Folders
\Junk E-mail
but the REAL Junk E-mail folder (i.e. the one that Outlook uses for
this account) is \[email protected]\Junk E-mail

How do I find the path to that?
 
K

Ken Slovak - [MVP - Outlook]

If that's the case Outlook is totally confused. GetDefaultFolder() will
always and only retrieve folders from your default PST file or Exchange
mailbox. It cannot retrieve folders from other mail stores that aren't the
default.

NameSpace.Folders has all your loaded PST files. You can iterate that
collection and its subfolders, etc. to find any loaded folder. The pattern
looks like this:
NameSpace.Folders.Item(1).Folders.Item("Inbox").Folders.Item("myInboxSubfolder"),
etc.
 
T

tnemec78

If that's the case Outlook is totally confused. GetDefaultFolder() will
always and only retrieve folders from your default PST file or Exchange
mailbox. It cannot retrieve folders from other mail stores that aren't the
default.

NameSpace.Folders has all your loaded PST files. You can iterate that
collection and its subfolders, etc. to find any loaded folder. The pattern
looks like this:
NameSpace.Folders.Item(1).Folders.Item("Inbox").Folders.Item("myInboxSubfolder"),
etc.

--
Ken Slovak
[MVP - Outlook]http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.http://www.slovaktech.com/products.htm


Firstly thank you very much for your quick reply, I really appreciate
it! I found out that this solution is almost there but not quite...
In my environment I have these Outlook folders:
\Personal Folders\
\Personal Folders\Deleted Items
\Personal Folders\Drafts
\Personal Folders\Inbox
\Personal Folders\Junk E-mail
\Personal Folders\Sent Items
...
\Archive Folders
\[email protected]\
\[email protected]\Inbox
\[email protected]\Inbox.Drafts
\[email protected]\Inbox.Sent
\[email protected]\Junk E-mail
...
The latter is my default data file or whatever it is called.
Now Session.GetDefaultFolder(olFolderJunk) points to \Private Folders
\Junk E-mail
but the REAL Junk E-mail folder (i.e. the one that Outlook uses for
this account) is \[email protected]\Junk E-mail
How do I find the path to that?

Thanks a lot. I have one more question regarding this:

Once a message is in a spam folder I guess there is no way to tell
where it came from? (in case I have implemented a more complex folder
logic instead of having just one Inbox folder)
 
K

Ken Slovak - [MVP - Outlook]

What do you mean by where it came from? Do you mean the sender? Nothing
changes with that.

If a spam comes in and gets directed to the Junk folder it obviously was
originally delivered to the Inbox, that's the only folder where the Junk
filter is active and the only place where incoming emails are delivered.




<snip>

Thanks a lot. I have one more question regarding this:

Once a message is in a spam folder I guess there is no way to tell
where it came from? (in case I have implemented a more complex folder
logic instead of having just one Inbox folder)
 
T

tnemec78

What do you mean by where it came from? Do you mean the sender? Nothing
changes with that.

If a spam comes in and gets directed to the Junk folder it obviously was
originally delivered to the Inbox, that's the only folder where the Junk
filter is active and the only place where incoming emails are delivered.

--
Ken Slovak
[MVP - Outlook]http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.http://www.slovaktech.com/products.htm


<snip>

Thanks a lot. I have one more question regarding this:

Once a message is in a spam folder I guess there is no way to tell
where it came from? (in case I have implemented a more complex folder
logic instead of having just one Inbox folder)

What I meant is that I many people sort their incoming mail into
different folders based on some sort of a logic (say Inbox, Family,
Friends, Client1, Client2, ...) and when such message get marked as
spam by mistake then my "Not Spam" button handler can only move it
back into the Inbox (thus not placing it in the correct inbox context
folder (ie. Family)). Or am I getting it wrong and anything that lands
inside Inbox gets filtered based on the filtering rules anyway?
 
K

Ken Slovak - [MVP - Outlook]

Anything that gets added to Inbox will fire the junk filter and any rules
you have set up. If something is classified as spam you normally whitelist
it and/or the sender, then you move it where you want if the rules don't do
it, or you manually run the rules.




<snip>

What I meant is that I many people sort their incoming mail into
different folders based on some sort of a logic (say Inbox, Family,
Friends, Client1, Client2, ...) and when such message get marked as
spam by mistake then my "Not Spam" button handler can only move it
back into the Inbox (thus not placing it in the correct inbox context
folder (ie. Family)). Or am I getting it wrong and anything that lands
inside Inbox gets filtered based on the filtering rules anyway?
 
T

tnemec78

Will it be possible to call

Store.GetSpecialFolder(olFolderJunk) to retrieve a junk folder for
every store instead of retrieving the generic one via
Session.GetDefaultFolder(olFolderJunk) ? And in a similar way marking
stuff as not spam would then move the item to Store.GetSpecialFolder
(olFolderInbox)

Does it make any sense?
 
K

Ken Slovak - [MVP - Outlook]

You can locate the junk folders for any store, but how they work is just as
normal folders in Outlook unless it's the junk folder for the default store.
That's the only one that will do the junk mail processing as items come in.
If you open a PST file as a secondary store that junk folder won't be
active.
 
T

tnemec78

OK I think I confused things a little bit. Now I am sure that I
finally found what I wanted to ask:

I found out that a store's Junk email can be identified as a 5th
element of the PR_ADDITIONAL_REN_ENTRYIDS IMAPIFolder property
Given a MailItem or a Folder instance how do I get that info? I assume
that I need to do something like this:

IUnknown *u;
folder->get_MAPIOBJECT(&u);
// will this give me the IMAPIFolder interface?
// How do I get the PR_ADDITIONAL_REN_ENTRYIDS property?
// How do I get the 5th element out of it?
// once I have it I can then do something like
namespace->GetFolderFromEntryID(entryID_received_from_steps_above);

Could you please shed some light on this? I did not find any source
code that does this. C# or C++ does not matter just as long as there
is something.

Many thanks
 
K

Ken Slovak - [MVP - Outlook]

I' not sure that's immutable and not dependent on the store provider, but
you get that PT_MV_BINARY property from the Inbox folder of a store using
the property tag 0x36D81102. Once you have that property it's just a array
of binary properties. So you get the 5th element of the array and then
convert that binary property into a hex string if you want.
 
T

tnemec78

I' not sure that's immutable and not dependent on the store provider, but
you get that PT_MV_BINARY property from the Inbox folder of a store using
the property tag 0x36D81102.

Can I find a source code anywhere that would show in detail how to do
this?
I don't know how to use property tag 0x36D81102 (I assume I do it
wrong)

void myfunction(CComPtr <Outlook::_MailItem> mi)
{
CComPtr <IDispatch> disp;
CComPtr <MAPIFolder> folder;
CComPtr <IUnknown> unk;
CComPtr <IMAPIFolder> ifolder;
SPropTagArray tags = {1, 0x36D81102/*PR_ADDITIONAL_REN_ENTRYIDS*/};
ULONG flags = 0, values;
LPSPropValue props;

mi->get_Parent(&disp);
disp->QueryInterface(__uuidof(MAPIFolder), (void **)&folder);
folder->get_MAPIOBJECT(&unk);
unk->QueryInterface(IID_IMAPIFolder, (void**)&ifolder);
ifolder->GetProps(&tags, flags, &values, &props);
...
at this point I think props should be filled with meaningfull data.
Debugger shows that props[0].Value.bin.cb == 6 but here the field props
[0].Value.bin.lb does not show anything similar to what OutlookSpy
shows :-(
 
T

tnemec78

Can I find a source code somewhere that shows how exatly do I get the
property with tag 0x36D81102 ???
I am probably doing something wrong. Here is what I do:

void myFunction(CComPtr <Outlook::_MailItem> mi)
{
CComPtr <IDispatch> disp;
CComPtr <MAPIFolder> folder;
CComPtr <IUnknown> unk;
CComPtr <IMAPIFolder> ifolder;
SPropTagArray tags = {1, 0x36D81102/*PR_ADDITIONAL_REN_ENTRYIDS*/};
ULONG flags = 0, values;
LPSPropValue props;

mi->get_Parent(&disp);
disp->QueryInterface(__uuidof(MAPIFolder), (void **)&folder);
folder->get_MAPIOBJECT(&unk);
unk->QueryInterface(IID_IMAPIFolder, (void**)&ifolder);
ifolder->GetProps(&tags, flags, &values, &props);
....
at this point props[0].Value.bin.cb == 6 according to the debugger but
props[0].Value.bin.lpb does not show anything similar to what
OutlookSpy reports :-(
 
K

Ken Slovak - [MVP - Outlook]

Unless Dmitry answers this you should post Extended MAPI questions in
microsoft.public.win32.programmer.messaging, where the MAPI people hang out.

Most of the examples for things like this I know of are for the Outlook or
Redemption object models.




I' not sure that's immutable and not dependent on the store provider, but
you get that PT_MV_BINARY property from the Inbox folder of a store using
the property tag 0x36D81102.

Can I find a source code anywhere that would show in detail how to do
this?
I don't know how to use property tag 0x36D81102 (I assume I do it
wrong)

void myfunction(CComPtr <Outlook::_MailItem> mi)
{
CComPtr <IDispatch> disp;
CComPtr <MAPIFolder> folder;
CComPtr <IUnknown> unk;
CComPtr <IMAPIFolder> ifolder;
SPropTagArray tags = {1, 0x36D81102/*PR_ADDITIONAL_REN_ENTRYIDS*/};
ULONG flags = 0, values;
LPSPropValue props;

mi->get_Parent(&disp);
disp->QueryInterface(__uuidof(MAPIFolder), (void **)&folder);
folder->get_MAPIOBJECT(&unk);
unk->QueryInterface(IID_IMAPIFolder, (void**)&ifolder);
ifolder->GetProps(&tags, flags, &values, &props);
...
at this point I think props should be filled with meaningfull data.
Debugger shows that props[0].Value.bin.cb == 6 but here the field props
[0].Value.bin.lb does not show anything similar to what OutlookSpy
shows :-(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top