1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-28 17:42:26 +01:00
Files
pentadactyl-pm/teledactyl/content/addressbook.js
Kris Maglione 1557b70f45 Major documentation updates and formatting fixes, and many, many other changes thanks to an MQ glitch, including:
* Significant completion speed improvements
 * Significantly improve startup speed, in large part by lazily
   instantiating Options and Commands, lazily installing highlight
   stylesheets, etc.
 * Update logos and icons, fix atrocious about page
 * Fix Teledactyl
 * JavaScript completion now avoids accessing property values
 * Add Option#persist to define which options are saved with :mkp
 * Add new Dactyl component which holds add-on-specific configuration
   information and removes need for separate components for each dactyl
   host
 * Several fixes for latest nightlies
 * Significant code cleanup and many bug fixes

--HG--
rename : muttator/AUTHORS => teledactyl/AUTHORS
rename : muttator/Donors => teledactyl/Donors
rename : muttator/Makefile => teledactyl/Makefile
rename : muttator/NEWS => teledactyl/NEWS
rename : muttator/TODO => teledactyl/TODO
rename : muttator/chrome.manifest => teledactyl/chrome.manifest
rename : muttator/components/commandline-handler.js => teledactyl/components/commandline-handler.js
rename : muttator/components/protocols.js => teledactyl/components/protocols.js
rename : muttator/content/addressbook.js => teledactyl/content/addressbook.js
rename : muttator/content/compose/compose.js => teledactyl/content/compose/compose.js
rename : muttator/content/compose/compose.xul => teledactyl/content/compose/compose.xul
rename : muttator/content/compose/dactyl.dtd => teledactyl/content/compose/dactyl.dtd
rename : muttator/content/compose/dactyl.xul => teledactyl/content/compose/dactyl.xul
rename : muttator/content/config.js => teledactyl/content/config.js
rename : muttator/content/dactyl.dtd => teledactyl/content/dactyl.dtd
rename : muttator/content/logo.png => teledactyl/content/logo.png
rename : muttator/content/mail.js => teledactyl/content/mail.js
rename : muttator/content/muttator.xul => teledactyl/content/pentadactyl.xul
rename : muttator/contrib/vim/Makefile => teledactyl/contrib/vim/Makefile
rename : muttator/contrib/vim/ftdetect/muttator.vim => teledactyl/contrib/vim/ftdetect/muttator.vim
rename : muttator/contrib/vim/mkvimball.txt => teledactyl/contrib/vim/mkvimball.txt
rename : muttator/contrib/vim/syntax/muttator.vim => teledactyl/contrib/vim/syntax/muttator.vim
rename : muttator/install.rdf => teledactyl/install.rdf
rename : muttator/locale/en-US/Makefile => teledactyl/locale/en-US/Makefile
rename : muttator/locale/en-US/all.xml => teledactyl/locale/en-US/all.xml
rename : muttator/locale/en-US/autocommands.xml => teledactyl/locale/en-US/autocommands.xml
rename : muttator/locale/en-US/gui.xml => teledactyl/locale/en-US/gui.xml
rename : muttator/locale/en-US/intro.xml => teledactyl/locale/en-US/intro.xml
rename : muttator/skin/icon.png => teledactyl/skin/icon.png
2010-09-17 06:21:33 -04:00

152 lines
5.7 KiB
JavaScript

// Copyright (c) 2008 by Christian Dietrich <stettberger@dokucode.de>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
const Addressbook = Module("addressbook", {
init: function () {
},
// TODO: add option for a format specifier, like:
// :set displayname=%l, %f
generateDisplayName: function (firstName, lastName) {
if (firstName && lastName)
return lastName + ", " + firstName;
else if (firstName)
return firstName;
else if (lastName)
return lastName;
else
return "";
},
getDirectoryFromURI: function (uri) services.get("rdf").GetResource(uri).QueryInterface(Ci.nsIAbDirectory),
add: function (address, firstName, lastName, displayName) {
const personalAddressbookURI = "moz-abmdbdirectory://abook.mab";
let directory = this.getDirectoryFromURI(personalAddressbookURI);
let card = Cc["@mozilla.org/addressbook/cardproperty;1"].createInstance(Ci.nsIAbCard);
if (!address || !directory || !card)
return false;
card.primaryEmail = address;
card.firstName = firstName;
card.lastName = lastName;
card.displayName = displayName;
return directory.addCard(card);
},
// TODO: add telephone number support
list: function (filter, newMail) {
let addresses = [];
let dirs = abManager.directories;
let lowerFilter = filter.toLowerCase();
while (dirs.hasMoreElements()) {
let addrbook = dirs.getNext().QueryInterface(Ci.nsIAbDirectory);
let cards = addrbook.childCards;
while (cards.hasMoreElements()) {
let card = cards.getNext().QueryInterface(Ci.nsIAbCard);
//var mail = card.primaryEmail || ""; //XXX
let displayName = card.displayName;
if (!displayName)
displayName = this.generateDisplayName(card.firstName, card.lastName);
if (displayName.toLowerCase().indexOf(lowerFilter) > -1
|| card.primaryEmail.toLowerCase().indexOf(lowerFilter) > -1)
addresses.push([displayName, card.primaryEmail]);
}
}
if (addresses.length < 1) {
if (!filter)
dactyl.echoerr("Exxx: No contacts", commandline.FORCE_SINGLELINE);
else
dactyl.echoerr("Exxx: No contacts matching string '" + filter + "'", commandline.FORCE_SINGLELINE);
return false;
}
if (newMail) {
// Now we have to create a new message
let args = {};
args.to = addresses.map(
function (address) "\"" + address[0].replace(/"/g, "") + " <" + address[1] + ">\""
).join(", ");
mail.composeNewMail(args);
}
else {
let list = template.tabular(["Name", "Address"], [],
[[util.clip(address[0], 50), address[1]] for ([, address] in Iterator(addresses))]
);
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
}
return true;
}
}, {
}, {
commands: function () {
commands.add(["con[tact]"],
"Add an address book entry",
function (args) {
let mailAddr = args[0]; // TODO: support more than one email address
let firstName = args["-firstname"] || null;
let lastName = args["-lastname"] || null;
let displayName = args["-name"] || null;
if (!displayName)
displayName = this.generateDisplayName(firstName, lastName);
if (addressbook.add(mailAddr, firstName, lastName, displayName))
dactyl.echomsg("Added address: " + displayName + " <" + mailAddr + ">", 1, commandline.FORCE_SINGLELINE);
else
dactyl.echoerr("Exxx: Could not add contact `" + mailAddr + "'", commandline.FORCE_SINGLELINE);
},
{
argCount: "+",
options: [[["-firstname", "-f"], commands.OPTION_STRING],
[["-lastname", "-l"], commands.OPTION_STRING],
[["-name", "-n"], commands.OPTION_STRING]]
});
commands.add(["contacts", "addr[essbook]"],
"List or open multiple addresses",
function (args) { addressbook.list(args.string, args.bang); },
{ bang: true });
},
mappings: function () {
var myModes = config.mailModes;
mappings.add(myModes, ["a"],
"Open a prompt to save a new addressbook entry for the sender of the selected message",
function () {
try {
var to = gDBView.hdrForFirstSelectedMessage.mime2DecodedAuthor;
}
catch (e) {
dactyl.beep();
}
if (!to)
return;
let address = to.substring(to.indexOf("<") + 1, to.indexOf(">"));
let displayName = to.substr(0, to.indexOf("<") - 1);
if (/^\S+\s+\S+\s*$/.test(displayName)) {
let names = displayName.split(/\s+/);
displayName = "-firstname=" + names[0].replace(/"/g, "")
+ " -lastname=" + names[1].replace(/"/g, "");
}
else
displayName = "-name=\"" + displayName.replace(/"/g, "") + "\"";
commandline.open(":", "contact " + address + " " + displayName, modes.EX);
});
}
});
// vim: set fdm=marker sw=4 ts=4 et: