MozillaZine

how do i get total msg size

Talk about add-ons and extension development.
nickhere
 
Posts: 40
Joined: September 29th, 2009, 1:57 pm

Post Posted October 29th, 2018, 8:01 pm

Code: Select all
function checkSubFolders(aFolder) {
  if (!aFolder.hasSubFolders) {
    return;
  }
  var enumerator = aFolder.subFolders;
  while (enumerator.hasMoreElements()) {
    var folder = enumerator.getNext().QueryInterface(Components.interfaces.nsIMsgFolder);
    //writeFile(file, account.incomingServer.prettyName + " " + folder.prettyName + '\n', false);
    var enumerator1 = folder.messages;
   // writeFile(file,enumerator1.length + '\n', false);
    //   while (enumerator1.hasMoreElements()) {
    //     var headerParser = Components.classes["@mozilla.org/messenger/headerparser;1"].getService(Components.interfaces.nsIMsgHeaderParser);
    //   var msgHdr = enumerator1.getNext().QueryInterface(Components.interfaces.nsIMsgDBHdr);
    //   var from = msgHdr.mime2DecodedAuthor;
    //   var to = msgHdr.mime2DecodedRecipients;
    //   var date = new Date(msgHdr.dateInSeconds * 1000).toLocaleString();
    //   var fromName = headerParser.extractHeaderAddressName(from);
    //   var fromMailboxes = headerParser.extractHeaderAddressMailboxes(from);
    //   writeFile(file, account.incomingServer.prettyName + " " + folder.prettyName + " " + fromName + " " + fromMailboxes +'\n', false);
    //   checkSubFolders(folder);   
    // }
   checkSubFolders(folder);   
  }
 
}


function writeFile(nsiFile, data, overwrite) {
  //overwrite is true false, if false then it appends
  //nsiFile must be nsiFile
  if (overwrite) {
    var openFlags = FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE;
  } else {
    var openFlags = FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_APPEND;
  } //data is data you want to write to file
  //if file doesnt exist it is created
  var ostream = FileUtils.openFileOutputStream(nsiFile, openFlags);
  ostream.write(data,data.length);
  ostream.close();

         
var acctMgr = Components.classes['@mozilla.org/messenger/account-manager;1'].getService(Components.interfaces.nsIMsgAccountManager);
var accounts = acctMgr.accounts;
var file = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsIFile);
file.initWithPath('d:\\ttt.txt');
for (var i = 0; i < accounts.length; i++) {
  var account = accounts.queryElementAt(i, Components.interfaces.nsIMsgAccount);
  //writeFile(file,account.incomingServer.prettyName + "\n",false);
  //console.log(account.incomingServer.prettyName);
  checkSubFolders(account.incomingServer.rootFolder);
}



in the upper code I have 2 enumertor which set up the loops
How do i pull the size.

morat
 
Posts: 3205
Joined: February 3rd, 2009, 6:29 pm

Post Posted October 30th, 2018, 12:04 am

Do you want the file size of a nsIFile?

Code: Select all
var file = Components.classes["@mozilla.org/file/local;1"].
  createInstance(Components.interfaces.nsIFile);
file.initWithPath("C:\\Windows\\System32\\notepad.exe");
alert(file.fileSize);

nickhere
 
Posts: 40
Joined: September 29th, 2009, 1:57 pm

Post Posted October 30th, 2018, 8:49 am

I want the size of the enumerator
I should be able to get the enumerate somehow

morat
 
Posts: 3205
Joined: February 3rd, 2009, 6:29 pm

Post Posted October 30th, 2018, 9:51 am

There is no length attribute for the nsISimpleEnumerator interface.

You can use a counter.

Code: Select all
var folder = gFolderDisplay.displayedFolder;
var enumerator = folder.messages;
var counter = 0;
while (enumerator.hasMoreElements()) {
  enumerator.getNext();
  counter++;
}
alert("Number of messages: " + counter);

Reference
http://developer.mozilla.org/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsISimpleEnumerator
http://developer.mozilla.org/docs/Mozilla/Tech/XPCOM/Using_nsISimpleEnumerator
http://dxr.mozilla.org/mozilla-esr60/source/xpcom/ds/nsISimpleEnumerator.idl

nickhere
 
Posts: 40
Joined: September 29th, 2009, 1:57 pm

Post Posted October 31st, 2018, 1:05 pm

I found out use fodler.getTotalMessage(0)
will get you the count
instead of emulating thru

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 2 guests