mkiol / GNotifier

Thunderbird add-on that replaces built-in notifications with the OS native notifications
https://addons.mozilla.org/thunderbird/addon/gnotifier/
GNU General Public License v3.0
164 stars 25 forks source link

Customizable notifications for Thunderbird #96

Closed gabrielfin closed 8 years ago

gabrielfin commented 8 years ago

I added the option to customize the notification content (for e-mails only) in Thunderbird. Basically, now there's two prefs, one to customize the title and another for the body of the notification. There you can set a string which may contain any of the following placeholders:

%s: Subject
%a: Sender (Name <E-mail>)
%m: Sender E-mail
%n: Sender Name
%f: Folder name
%v: Server address
%k: Message size
%u: Account name
%b: Body excerpt (first 80 characters)
%%: % symbol,
\n: Newline (only for notification body)

I also added a button to test the notification system (especially useful for this new feature), that uses the currently selected e-mail (in the main window/tab) as example.

Just in case, a few comments for clarification:

I used gHeaderParser.parseDecodedHeader(message.mime2DecodedAuthor) to separate sender name from sender email, which seems better than using regex.

I split showNewMessageNotification into showNewRSSNotification and showNewEmailNotification, since now they are completely different. Maybe they could be merged again sometime if we enable notification customization for RSS as well.

The format function receives a callback because obtaining the body of a message is asynchronous. From that I infer that it's not immediate, therefore I only use it if necessary (i.e. the format string actually contains %b). All the callback hassle in showNewMessageNotification and format is because of that. Maybe there's a prettier way to do it?

mkiol commented 8 years ago

It looks amazing! Before merging, I want to go thought all my test cases, just to be sure that everything is fine. Please give me a day to do that.

PS: Button for testing is extremely useful :-)

mkiol commented 8 years ago

Works like a charm! Thank you so much for the contribution.