MozillaZine

Where is there a good tutorial on how to build a thunderbird

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

Post Posted October 30th, 2017, 2:19 pm

MY sister has over 50,000 msg in her inbox.
What I want the add on to do is read all the mail address and names in her inbox
Sort it by name then by email address
create the directory by name then by adddress on the local folder
then make and run the filters

I know how to make and load a temporary add on
manifest and javascript.
but how do i access and loop the proper section

DanRaisch
Moderator

User avatar
 
Posts: 117741
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Post Posted October 30th, 2017, 3:30 pm

Moving to Extension Development.

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

Post Posted October 31st, 2017, 9:33 am

What did you come up with?

Original thread: viewtopic.php?f=39&t=3032139

Here is how to get the "Local Folders" folder.

Code: Select all
var accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].
  getService(Components.interfaces.nsIMsgAccountManager);
var localFoldersFolder = accountManager.localFoldersServer.rootFolder;

Do you want to create subfolders based on the header address names? Some of these may be illegal folder names.

nsIMsgFolder.createSubfolder
http://dxr.mozilla.org/comm-release/source/mailnews/base/public/nsIMsgFolder.idl

Here is how to show a list of unique header address names with count in a new tab. (sorted alphabetically)

Code: Select all
function openTab(aString) {
  var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].
    createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
  converter.charset = "UTF-8";
  aString = converter.ConvertFromUnicode(aString);
  aString = aString.replace(/&/g, "&");
  aString = aString.replace(/>/g, ">");
  aString = aString.replace(/</g, "&lt;");
  aString = aString.replace(/"/g, "&quot;");
  aString = aString.replace(/'/g, "&apos;");
  var data = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">';
  data += "<html><head><title>Authors</title>";
  data += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
  data += "</head><body><pre>" + aString + "</pre></body></html>";
  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
    getService(Components.interfaces.nsIWindowMediator);
  var win = wm.getMostRecentWindow("mail:3pane");
  win.document.getElementById("tabmail").openTab("contentTab", {
    contentPage: "data:text/html;charset=utf-8;base64," + btoa(data),
    background: true});
}
var headerParser = Components.classes["@mozilla.org/messenger/headerparser;1"].
  getService(Components.interfaces.nsIMsgHeaderParser);
var folder = GetFirstSelectedMsgFolder();
var enumerator = folder.messages;
var fromNameArray = [];
var fromNameCounter = {};
while (enumerator.hasMoreElements()) {
  var msgHdr = enumerator.getNext().QueryInterface(Components.interfaces.nsIMsgDBHdr);
  var subject = msgHdr.mime2DecodedSubject;
  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);
  if (fromNameArray.indexOf(fromName) === -1) {
    fromNameArray.push(fromName); // unique
  }
  fromNameCounter[fromName] = fromNameCounter[fromName] ? fromNameCounter[fromName] + 1 : 1;
}
fromNameArray = fromNameArray.sort();
for (var i = 0; i < fromNameArray.length; i++) {
  fromNameArray[i] = (i + 1) + ". " + fromNameArray[i] + " - " + fromNameCounter[fromNameArray[i]];
}
openTab(fromNameArray.join("\n"));

Why do you want to create filters to copy messages? Why not just copy messages?

nsIMsgCopyService.CopyMessages
http://dxr.mozilla.org/comm-release/source/mailnews/base/public/nsIMsgCopyService.idl
http://dxr.mozilla.org/comm-release/source/mailnews/base/public/nsIMsgCopyServiceListener.idl
Last edited by morat on October 31st, 2017, 11:39 pm, edited 1 time in total.

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

Post Posted October 31st, 2017, 11:49 am

her filter is empty i want it to move on new msg
thank for getting me started

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

Post Posted October 31st, 2017, 5:20 pm

Here is how to show a list with the FiltaQuilla extension.

http://addons.mozilla.org/thunderbird/a ... ltaquilla/
http://mesquilla.com/extensions/filtaquilla/

Code: Select all
/*Javascript Action*/
function openTab(aString) {
  var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].
    createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
  converter.charset = "UTF-8";
  aString = converter.ConvertFromUnicode(aString);
  aString = aString.replace(/&/g, "&amp;");
  aString = aString.replace(/>/g, "&gt;");
  aString = aString.replace(/</g, "&lt;");
  aString = aString.replace(/"/g, "&quot;");
  aString = aString.replace(/'/g, "&apos;");
  var data = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">';
  data += "<html><head><title>Authors</title>";
  data += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
  data += "</head><body><pre>" + aString + "</pre></body></html>";
  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
    getService(Components.interfaces.nsIWindowMediator);
  var win = wm.getMostRecentWindow("mail:3pane");
  win.document.getElementById("tabmail").openTab("contentTab", {
    contentPage: "data:text/html;charset=utf-8;base64," + btoa(data),
    background: true});
}
var headerParser = Components.classes["@mozilla.org/messenger/headerparser;1"].
  getService(Components.interfaces.nsIMsgHeaderParser);
var fromNameArray = [];
var fromNameCounter = {};
for (var i = 0; i < msgHdrs.length; i++) {
  var msgHdr = msgHdrs.queryElementAt(i, Components.interfaces.nsIMsgDBHdr);
  var subject = msgHdr.mime2DecodedSubject;
  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);
  if (fromNameArray.indexOf(fromName) === -1) {
    fromNameArray.push(fromName); // unique
  }
  fromNameCounter[fromName] = fromNameCounter[fromName] ? fromNameCounter[fromName] + 1 : 1;
}
fromNameArray = fromNameArray.sort();
for (var i = 0; i < fromNameArray.length; i++) {
  fromNameArray[i] = (i + 1) + ". " + fromNameArray[i] + " - " + fromNameCounter[fromNameArray[i]];
}
openTab(fromNameArray.join("\n"));

I'm not familiar with filter creation, so I'm not much help to you.

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 2 guests