Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IMAP: Getting message key of copied message by nsIMsgCopyService::CopyFileMessage

62 views
Skip to first unread message

Pavol Misik

unread,
May 14, 2009, 4:21:06 AM5/14/09
to
Hi,

I'm using nsIMsgCopyService::CopyFileMessage to copy a mail in rfc
format from file to IMAP folder.

nsCOMPtr<nsIMsgCopyServiceListener> listener = new
MyCopyServiceListener(this);

rv = copyService->CopyFileMessage(fileSpec, destFolder, nsnull,
PR_FALSE, m_flags, listener, m_msgWnd);


I need to get id of message after message is copied to folder.
I expected that nsIMsgCopyServiceListener::SetMessageKey will be called
and I get message key of new message. But it doesn�t happen.

I investigated which methods of nsIMsgCopyServiceListener are called.
I find out that only:
void OnStartCopy(); and
void OnStopCopy(in nsresult aStatus);

are called. A value of variable aStatus in OnStopCopy is NS_OK and
message is really successfully copied, but I don�t have message key or Id.

In nsIMsgCopyServiceListener.idl is written this for SetMessageKey:

* Setting newly created message key. This method is taylored specifically
* for nsIMsgCopyService::CopyFileMessage() when saveing Drafts/Templates.
* We need to have a way to inform the client what's the key of the newly
* created message.

Does it mean that is called only for Drafts/Templates folder?
Does it exist any way how to get message key or any other identification
which can help me get nsIMsgHdr of newly copied message?

Thanks for any advice.


PM

Siddharth Agarwal

unread,
May 14, 2009, 5:03:09 AM5/14/09
to
On 14-05-2009 13:51, Pavol Misik wrote:
> Hi,
>
> I'm using nsIMsgCopyService::CopyFileMessage to copy a mail in rfc
> format from file to IMAP folder.
>
> nsCOMPtr<nsIMsgCopyServiceListener> listener = new
> MyCopyServiceListener(this);
>
> rv = copyService->CopyFileMessage(fileSpec, destFolder, nsnull,
> PR_FALSE, m_flags, listener, m_msgWnd);
>

I remember investigating this a while ago while writing a unit test. I
don't remember the exact details right now, but what happens when you
set the fourth argument to PR_TRUE?

Siddharth

Pavol Misik

unread,
May 14, 2009, 6:53:25 AM5/14/09
to

Andrew Sutherland

unread,
May 14, 2009, 9:55:57 AM5/14/09
to
On 05/14/2009 01:21 AM, Pavol Misik wrote:
> I'm using nsIMsgCopyService::CopyFileMessage to copy a mail in rfc
> format from file to IMAP folder.

Because it is an IMAP folder, we don't know the UID of the message until
we enter it. (In IMAP folders, the UID is the message key.)

So you have two problems:
1) Make sure the IMAP folder is up-to-date.
2) Figure out which message it is in that folder.

For #1, maybe perhaps call updateFolder on the nsIMsgFolder. I think
updateFolder may be a bit heavy-handed, but I'm not sure what the
appropriate call is.

For #2, the most reliable way would probably be to use the
nsIMsgDatabase's ability to find a message given its message-id header
value. If you were trying to be more efficient, you could make sure you
have a listener setup before you perform the copy that will notify you
when messages are added to the target folder. Then the message would
show up that way, although you potentially would have to ignore the
addition of messages you do not care about.

Andrew

Pavol Misik

unread,
May 14, 2009, 10:58:13 AM5/14/09
to

I find out that when I work with IMAP server which supports IMAP4
UIDPLUS extension then I get message key. Otherwise I don't get it.
Fourth argument doesn't affect behavior.

PM

0 new messages