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

Forcing Persist Service to Finish

13 views
Skip to first unread message

Khalid Latif

unread,
Oct 30, 2006, 12:20:15 PM10/30/06
to
I have developed an extension for TBird for archiving messages to my own
repository. Because I don't know how to read the message source into a
buffer, I write it into a temporary file using nsIWebBrowserPersist
service and then read the file into a buffer.

The nsIWebBrowserPersist service seems to be asynchronous as immediately
reading the file causes error as the saveURI method might not have done
its work. As a way out I repeatedly display alert showing "currentState"
until its value is PERSIST_STATE_FINISHED. After one or at most two
alerts it proceeds to the next code.

My question is, Is there any elegant way of forcing nsWebBrowserPersist
service to finish its job? Alternatively a method to read the message
source directly into a buffer will be appreciated.


Currently the code looks like this:

const nsIWBP = Components.interfaces.nsIWebBrowserPersist;
var persist =
Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(nsIWBP);
persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES
| nsIWBP.PERSIST_FLAGS_FROM_CACHE;

persist.saveURI(msgURI, null, null, null, null, localFile);

// force to complete
while(persist.currentState != persist.PERSIST_STATE_FINISHED)
alert(persist.currentState);

// further work


Regards,
Khalid

0 new messages