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

  • Thread starter tnemec78@googlemail.com
  • Start date Views 3,707
Status
Not open for further replies.
T

tnemec78@googlemail.com

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]

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

NameSpace.GetDefaultFolder(OlDefaultFolders.olFolderJunk) will work for any

Outlook version that has a Junk folder. That's language independent.

<tnemec78@googlemail.com> wrote in message

news:0a738f4c-6d45-442f-84f3-9b397c79e357@o20g2000vbh.googlegroups.com...
> 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
 
T

tnemec78@googlemail.com

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

\user@server.com\

\user@server.com\Inbox

\user@server.com\Inbox.Drafts

\user@server.com\Inbox.Sent

\user@server.com\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 \user@server.com\Junk E-mail

How do I find the path to that?
 
K

Ken Slovak - [MVP - Outlook]

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

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.

<tnemec78@googlemail.com> wrote in message

news:c16da584-2596-4733-80da-0f862482e27c@r36g2000vbr.googlegroups.com...
> 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
> \user@server.com\
> \user@server.com\Inbox
> \user@server.com\Inbox.Drafts
> \user@server.com\Inbox.Sent
> \user@server.com\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 \user@server.com\Junk E-mail

> How do I find the path to that?
 
T

tnemec78@googlemail.com

On 14 kvì, 20:35, " - " <kenslo...@mvps.org
wrote:
> 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.

> >

> http://www.slovaktech.com

> <tneme...@googlemail.com> wrote in message

> news:c16da584-2596-4733-80da-0f862482e27c@r36g2000vbr.googlegroups.com...
>
> > 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
> > \u...@server.com\
> > \u...@server.com\Inbox
> > \u...@server.com\Inbox.Drafts
> > \u...@server.com\Inbox.Sent
> > \u...@server.com\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 \u...@server.com\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]

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

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.

<tnemec78@googlemail.com> wrote in message

news:b4500543-e1ee-4206-9b9f-9ba239e27765@z19g2000vbz.googlegroups.com...

<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@googlemail.com

On 15 kvì, 15:04, " - " <kenslo...@mvps.org
wrote:
> 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.

> >

> http://www.slovaktech.com

> <tneme...@googlemail.com> wrote in message

> news:b4500543-e1ee-4206-9b9f-9ba239e27765@z19g2000vbz.googlegroups.com...
> <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]

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

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.

<tnemec78@googlemail.com> wrote in message

news:39be620e-a3bf-4158-a3c1-385eeff5060b@l28g2000vba.googlegroups.com...

<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@googlemail.com

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]

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

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.

<tnemec78@googlemail.com> wrote in message

news:e374703c-6937-4aa7-92cd-4f93c2b3cee9@s21g2000vbb.googlegroups.com...
> 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?
 
T

tnemec78@googlemail.com

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]

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

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.

<tnemec78@googlemail.com> wrote in message

news:982d303c-a43c-4ff4-a5fc-22b81ccbdf71@j12g2000vbl.googlegroups.com...
> 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
 
T

tnemec78@googlemail.com

> 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@googlemail.com

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]

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

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.

<tnemec78@googlemail.com> wrote in message

news:85bfebba-d659-4190-b583-d487e9f90468@v4g2000vba.googlegroups.com...
> > 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 :-(
 
Status
Not open for further replies.
Top