branch: externals/ebdb commit 784d66990f59fcfd0e9de8b91d5f6d39ba7426ff Author: Eric Abrahamsen <e...@ericabrahamsen.net> Commit: Eric Abrahamsen <e...@ericabrahamsen.net>
New option ebdb-gnus-post-style-function * ebdb-gnus.el (ebdb-gnus-post-style-function): Callable allowing users to set up Gnus posting styles depending on the recipient record of a message. (ebdb-field-mail-compose): Method specialized on value of `read-mail-command'. Runs the above function and optionally sets the value of `gnus-newsgroup-name'. * ebdb.org: Document. --- ebdb-gnus.el | 31 +++++++- ebdb.info | 243 ++++++++++++++++++++++++++++++++++++++--------------------- ebdb.org | 39 ++++++++++ ebdb.texi | 63 ++++++++++++++++ 4 files changed, 290 insertions(+), 86 deletions(-) diff --git a/ebdb-gnus.el b/ebdb-gnus.el index 6938c8e..c034143 100644 --- a/ebdb-gnus.el +++ b/ebdb-gnus.el @@ -26,7 +26,7 @@ (require 'ebdb-com) (require 'ebdb-mua) (require 'gnus-sum) -(require 'gnus-art) +(require 'gnus-msg) (autoload 'message-make-domain "message") @@ -57,6 +57,20 @@ article buffer, taking up 40% of the horizontal space." :group 'ebdb-mua-gnus :type 'list) +(defcustom ebdb-gnus-post-style-function + (lambda (_rec _mail) nil) + "Callable used to determine Gnus group posting styles. +The callable should accept a single record as a first argument, +and a mail field instance as a second. Either return a Gnus +group name as a string, which will be used to configure posting +styles when composing a message to that record/mail, or return +nil to use Gnus defaults. + +See `ebdb-record-field' or `ebdb-record-current-fields' for +likely ways to extract information about the record." + :group 'ebdb-mua-gnus + :type 'function) + (defgroup ebdb-mua-gnus-scoring nil "Gnus-specific scoring EBDB customizations" :group 'ebdb-mua-gnus) @@ -301,6 +315,21 @@ quoted replies." (or (re-search-forward "\n\n" nil t) (point-max))))) +(cl-defmethod ebdb-field-mail-compose ((record ebdb-record-entity) + (mail ebdb-field-mail) + &context (read-mail-command (eql gnus)) + &rest args) + "Compose a Gnus mail to RECORD's address MAIL. +Gives the user a chance to set posting styles for a message +composed to a certain record." + (let ((group (funcall ebdb-gnus-post-style-function + record mail))) + (if group + (let ((gnus-newsgroup-name group)) + (gnus-setup-message 'message + (apply #'message-mail (ebdb-dwim-mail record mail) args))) + (cl-call-next-method)))) + (defun ebdb-insinuate-gnus () "Hook EBDB into Gnus." ;; `ebdb-mua-display-sender' fails in *Article* buffers, where diff --git a/ebdb.info b/ebdb.info index 10bf542..f79b37f 100644 --- a/ebdb.info +++ b/ebdb.info @@ -30,6 +30,7 @@ EBDB Manual * Creating Records:: * Record Fields:: * MUA Interaction:: +* Specific MUAs:: * EBDB Buffers:: * Completion:: * Snarfing:: @@ -94,6 +95,15 @@ EBDB and MUA summary buffers * Summary buffer marks:: +Specific MUAs + +* Gnus:: + +Gnus + +* Posting Styles:: + + EBDB Buffers * Searching:: @@ -527,7 +537,7 @@ incoming mail from the contact should be filed into. Currently only Gnus supports this; support in other MUAs is forthcoming. -File: ebdb.info, Node: MUA Interaction, Next: EBDB Buffers, Prev: Record Fields, Up: Top +File: ebdb.info, Node: MUA Interaction, Next: Specific MUAs, Prev: Record Fields, Up: Top 5 MUA Interaction ***************** @@ -846,9 +856,68 @@ string provided by Gnus, and adding the EBDB-specific format code: record. Defaults to “e”. -File: ebdb.info, Node: EBDB Buffers, Next: Completion, Prev: MUA Interaction, Up: Top +File: ebdb.info, Node: Specific MUAs, Next: EBDB Buffers, Prev: MUA Interaction, Up: Top + +6 Specific MUAs +*************** + +* Menu: + +* Gnus:: + + +File: ebdb.info, Node: Gnus, Up: Specific MUAs + +6.1 Gnus +======== + +EBDB has a little more support for Gnus than the other MUAs, for no +other reason than that Gnus is what the author uses. + +* Menu: + +* Posting Styles:: + + +File: ebdb.info, Node: Posting Styles, Up: Gnus + +6.1.1 Posting Styles +-------------------- + +Gnus provides a “posting styles” mechanism which allows the user to set +up specific mail composition styles (custom headers and signatures, etc) +when writing mails to certain recipients. The mechanism examines Gnus +group names to determine which styles to use. EBDB can fake this +mechanism so that different styles are used when composing messages to +different records. + + -- User Option: ebdb-gnus-post-style-function + Set this option to a callable which accepts two arguments, a record + instance and a mail instance. The callable should examine these + arguments and return the string name of a Gnus group to use for + looking up posting styles, or nil to use Gnus’ defaults. + + When writing this function, functions such as ‘ebdb-record-field’ and +‘ebdb-record-current-fields’ may come in handy. Here’s a less-obvious +example that dispatches styles depending on which database the record +belongs to: + + (setq ebdb-gnus-post-style-function + (lambda (rec _mail) + (let ((dbs (slot-value (ebdb-record-cache rec) 'database))) + (if (object-assoc "File: work.dat" 'label dbs) + "nnimap+WorkAccount:INBOX" + "nnimap+PersonalAccount:INBOX")))) + + A current limitation of this functionality is that it only works when +composing a mail to a single recipient. If you mark several records in +a *EBDB* buffer and compose a mail to them collectively, the mechanism +will be bypassed. + + +File: ebdb.info, Node: EBDB Buffers, Next: Completion, Prev: Specific MUAs, Up: Top -6 EBDB Buffers +7 EBDB Buffers ************** EBDB can create several separate buffers for displaying contacts. @@ -883,7 +952,7 @@ existing EBDB buffers. File: ebdb.info, Node: Searching, Next: The Basics of ebdb-mode, Up: EBDB Buffers -6.1 Searching +7.1 Searching ============= The most general search is performed with ‘/ /’, which searches on many @@ -944,7 +1013,7 @@ buffer. To pop back to previous searches, use: File: ebdb.info, Node: Changing Search Behavior, Up: Searching -6.1.1 Changing Search Behavior +7.1.1 Changing Search Behavior ------------------------------ There are three ways to alter the behavior of EBDB searches. @@ -974,7 +1043,7 @@ possibility for unexpected search behavior. File: ebdb.info, Node: The Basics of ebdb-mode, Next: Customizing Record Display, Prev: Searching, Up: EBDB Buffers -6.2 The Basics of ebdb-mode +7.2 The Basics of ebdb-mode =========================== EBDB buffers inherit from special-mode, and so the usual special-mode @@ -1102,7 +1171,7 @@ creation and field manipulation. File: ebdb.info, Node: Customizing Record Display, Next: Marking, Prev: The Basics of ebdb-mode, Up: EBDB Buffers -6.3 Customizing Record Display +7.3 Customizing Record Display ============================== The appearance of records in *EBDB* buffers can be customized. The @@ -1199,7 +1268,7 @@ to get things exactly right, but the general signature looks like: File: ebdb.info, Node: Marking, Next: Exporting/Formatting, Prev: Customizing Record Display, Up: EBDB Buffers -6.4 Marking +7.4 Marking =========== Records can be marked and acted on in bulk. The ‘#’ key will toggle the @@ -1210,7 +1279,7 @@ Many editing commands can act on multiple marked records. File: ebdb.info, Node: Exporting/Formatting, Prev: Marking, Up: EBDB Buffers -6.5 Exporting/Formatting +7.5 Exporting/Formatting ======================== It is possible to export (referred to as “formatting”) records in @@ -1235,7 +1304,7 @@ is unsupported: the only options are version 3.0 and 4.0. File: ebdb.info, Node: Completion, Next: Snarfing, Prev: EBDB Buffers, Up: Top -7 Completion +8 Completion ************ There are many Emacs completion frameworks out there, and libraries @@ -1260,7 +1329,7 @@ completion frameworks. File: ebdb.info, Node: Snarfing, Next: Internationalization, Prev: Completion, Up: Top -8 Snarfing +9 Snarfing ********** “Snarfing” refers to scanning free-form text and extracting information @@ -1305,8 +1374,8 @@ article headers. File: ebdb.info, Node: Internationalization, Next: Diary Integration, Prev: Snarfing, Up: Top -9 Internationalization -********************** +10 Internationalization +*********************** EBDB comes with an internationalization framework that can provide country- and region-specific behavior for certain fields. This @@ -1358,7 +1427,7 @@ alter the display of some country names if they choose. File: ebdb.info, Node: Diary Integration, Next: Mail Aliases, Prev: Internationalization, Up: Top -10 Diary Integration +11 Diary Integration ******************** Some EBDB fields hold dates or anniversaries (most notably the @@ -1381,7 +1450,7 @@ are forthcoming. File: ebdb.info, Node: Mail Aliases, Next: vCard Support, Prev: Diary Integration, Up: Top -11 Mail Aliases +12 Mail Aliases *************** You can give records a mail alias with the “mail alias” field, available @@ -1397,7 +1466,7 @@ also possible to force an update using the ‘A’ key in a *EBDB* buffer. File: ebdb.info, Node: vCard Support, Next: Org Integration, Prev: Mail Aliases, Up: Top -12 vCard Support +13 vCard Support **************** EBDB has rudimentary support for exporting to vCard format; this @@ -1411,7 +1480,7 @@ eventually, support for CardDav servers. File: ebdb.info, Node: Org Integration, Next: Citing Records, Prev: vCard Support, Up: Top -13 Org Integration +14 Org Integration ****************** EBDB has standard support for Org functionality: creating links to EBDB @@ -1451,7 +1520,7 @@ pop up a buffer any time relevant records are found. File: ebdb.info, Node: Citing Records, Next: Hacking EBDB, Prev: Org Integration, Up: Top -14 Citing Records +15 Citing Records ***************** Often one wants to share contact information into other channels: for @@ -1469,7 +1538,7 @@ a general interface to this through: File: ebdb.info, Node: Hacking EBDB, Next: Index, Prev: Citing Records, Up: Top -15 Hacking EBDB +16 Hacking EBDB *************** EBDB is designed to be highly extensible. In addition to the usual @@ -1531,7 +1600,7 @@ existing objects. This may be addressed in the future. File: ebdb.info, Node: Field Classes, Next: Writing Internationalization Libraries, Up: Hacking EBDB -15.1 Field Classes +16.1 Field Classes ================== It’s fairly easy to create your own custom field classes in EBDB. All @@ -1603,7 +1672,7 @@ default values for the new object. File: ebdb.info, Node: Init and Delete Methods, Next: The Labeled Field Class, Up: Field Classes -15.1.1 Init and Delete Methods +16.1.1 Init and Delete Methods ------------------------------ It’s also very common to define ‘ebdb-init-field’ and @@ -1641,7 +1710,7 @@ must not change the database: they may not edit records or their fields. File: ebdb.info, Node: The Labeled Field Class, Next: The Singleton Field Class, Prev: Init and Delete Methods, Up: Field Classes -15.1.2 The Labeled Field Class +16.1.2 The Labeled Field Class ------------------------------ Many field classes maintain their own list of labels: ie, anniversary @@ -1660,7 +1729,7 @@ used to hold labels, and pointing to it in the class-allocated File: ebdb.info, Node: The Singleton Field Class, Next: Actions, Prev: The Labeled Field Class, Up: Field Classes -15.1.3 The Singleton Field Class +16.1.3 The Singleton Field Class -------------------------------- Another abstract mix-in class is the ‘ebdb-field-singleton’ class. Its @@ -1671,7 +1740,7 @@ existing instance is deleted. File: ebdb.info, Node: Actions, Next: Custom Field Searching, Prev: The Singleton Field Class, Up: Field Classes -15.1.4 Actions +16.1.4 Actions -------------- All field classes have a class-allocated slot called “actions”. The @@ -1687,7 +1756,7 @@ and the field instance under point. File: ebdb.info, Node: Custom Field Searching, Next: Fast Lookups, Prev: Actions, Up: Field Classes -15.1.5 Custom Field Searching +16.1.5 Custom Field Searching ----------------------------- In most cases, searching the EBDB database is a matter of prompting for @@ -1748,7 +1817,7 @@ EBDB code would create this search, external code conceivably might. File: ebdb.info, Node: Fast Lookups, Next: Formatting in the EBDB Buffer, Prev: Custom Field Searching, Up: Field Classes -15.1.6 Fast Lookups +16.1.6 Fast Lookups ------------------- Usually, searches of the database are conducted by looping over all the @@ -1784,7 +1853,7 @@ match the instance of that field (and not some other field string). File: ebdb.info, Node: Formatting in the EBDB Buffer, Prev: Fast Lookups, Up: Field Classes -15.1.7 Formatting in the EBDB Buffer +16.1.7 Formatting in the EBDB Buffer ------------------------------------ Most fields will be displayed in the *EBDB* buffer simply using @@ -1827,7 +1896,7 @@ used in the body of the method. File: ebdb.info, Node: Writing Internationalization Libraries, Next: Writing Integration For New MUAs, Prev: Field Classes, Up: Hacking EBDB -15.2 Writing Internationalization Libraries +16.2 Writing Internationalization Libraries =========================================== Writing new internationalization libraries involves using generic @@ -1923,7 +1992,7 @@ be specialized on with the ‘eql’ specializer. File: ebdb.info, Node: Writing Integration For New MUAs, Prev: Writing Internationalization Libraries, Up: Hacking EBDB -15.3 Writing Integration For New MUAs +16.3 Writing Integration For New MUAs ===================================== Theoretically EBDB can be incorporated into any Emacs package, but it’s @@ -1998,7 +2067,7 @@ functions. File: ebdb.info, Node: Article snarfing, Up: Writing Integration For New MUAs -15.3.1 Article snarfing +16.3.1 Article snarfing ----------------------- EBDB can scan articles or messages for likely field information, and @@ -2164,6 +2233,7 @@ Index (line 20) * ebdb-format-to-tmp-buffer: Exporting/Formatting. (line 15) +* ebdb-gnus-post-style-function: Posting Styles. (line 13) * ebdb-hash-extra-predicates: Fast Lookups. (line 30) * ebdb-hashtable: Fast Lookups. (line 10) * ebdb-help: The Basics of ebdb-mode. @@ -2362,61 +2432,64 @@ Index Tag Table: Node: Top806 -Node: Getting Started2456 -Node: Migration from BBDB3111 -Node: Record Migration3322 -Node: Variables and Options4125 -Node: Migration from Org Contacts4611 -Node: The EBDB Database5371 -Node: Creating Records9359 -Node: Record classes10440 -Node: Record names10785 -Node: Record Fields11460 -Node: Inserting New Fields11704 -Node: Editing Existing Fields12500 -Node: Deleting Records and Fields13100 -Node: Field Types13496 -Node: Role fields15783 -Node: Tag field17471 -Node: Mail folder field18115 -Node: MUA Interaction18443 -Node: Loading MUA Code18967 -Node: Display and Updating19680 -Node: Pop-up Buffers20446 -Node: Auto-Updating Records22029 -Node: Noticing and Automatic Rules24429 -Node: Interactive Commands25762 -Node: EBDB and MUA summary buffers28237 -Node: Sender name display28723 -Node: Summary buffer marks29950 -Node: EBDB Buffers31129 -Node: Searching32342 -Node: Changing Search Behavior34004 -Node: The Basics of ebdb-mode35251 -Node: Customizing Record Display39566 -Node: Marking43886 -Node: Exporting/Formatting44313 -Node: Completion45262 -Node: Snarfing46460 -Node: Internationalization48477 -Node: Diary Integration51176 -Node: Mail Aliases52041 -Node: vCard Support52755 -Node: Org Integration53254 -Node: Citing Records55152 -Node: Hacking EBDB55910 -Node: Field Classes58229 -Node: Init and Delete Methods61360 -Node: The Labeled Field Class62867 -Node: The Singleton Field Class63721 -Node: Actions64159 -Node: Custom Field Searching64831 -Node: Fast Lookups67698 -Node: Formatting in the EBDB Buffer69508 -Node: Writing Internationalization Libraries71584 -Node: Writing Integration For New MUAs75998 -Node: Article snarfing79445 -Node: Index80163 +Node: Getting Started2526 +Node: Migration from BBDB3181 +Node: Record Migration3392 +Node: Variables and Options4195 +Node: Migration from Org Contacts4681 +Node: The EBDB Database5441 +Node: Creating Records9429 +Node: Record classes10510 +Node: Record names10855 +Node: Record Fields11530 +Node: Inserting New Fields11774 +Node: Editing Existing Fields12570 +Node: Deleting Records and Fields13170 +Node: Field Types13566 +Node: Role fields15853 +Node: Tag field17541 +Node: Mail folder field18185 +Node: MUA Interaction18513 +Node: Loading MUA Code19038 +Node: Display and Updating19751 +Node: Pop-up Buffers20517 +Node: Auto-Updating Records22100 +Node: Noticing and Automatic Rules24500 +Node: Interactive Commands25833 +Node: EBDB and MUA summary buffers28308 +Node: Sender name display28794 +Node: Summary buffer marks30021 +Node: Specific MUAs31200 +Node: Gnus31348 +Node: Posting Styles31570 +Node: EBDB Buffers33145 +Node: Searching34356 +Node: Changing Search Behavior36018 +Node: The Basics of ebdb-mode37265 +Node: Customizing Record Display41580 +Node: Marking45900 +Node: Exporting/Formatting46327 +Node: Completion47276 +Node: Snarfing48474 +Node: Internationalization50491 +Node: Diary Integration53192 +Node: Mail Aliases54057 +Node: vCard Support54771 +Node: Org Integration55270 +Node: Citing Records57168 +Node: Hacking EBDB57926 +Node: Field Classes60245 +Node: Init and Delete Methods63376 +Node: The Labeled Field Class64883 +Node: The Singleton Field Class65737 +Node: Actions66175 +Node: Custom Field Searching66847 +Node: Fast Lookups69714 +Node: Formatting in the EBDB Buffer71524 +Node: Writing Internationalization Libraries73600 +Node: Writing Integration For New MUAs78014 +Node: Article snarfing81461 +Node: Index82179 End Tag Table diff --git a/ebdb.org b/ebdb.org index 1f46c20..a019ed7 100644 --- a/ebdb.org +++ b/ebdb.org @@ -703,6 +703,45 @@ string provided by Gnus, and adding the EBDB-specific format code: Format letter to use in the summary buffer format string to mark a record. Defaults to "e". #+END_defopt +* Specific MUAs +** Gnus +EBDB has a little more support for Gnus than the other MUAs, for no +other reason than that Gnus is what the author uses. +*** Posting Styles +Gnus provides a "posting styles" mechanism which allows the user to +set up specific mail composition styles (custom headers and +signatures, etc) when writing mails to certain recipients. The +mechanism examines Gnus group names to determine which styles to use. +EBDB can fake this mechanism so that different styles are used when +composing messages to different records. + +#+attr_texinfo: :options ebdb-gnus-post-style-function +#+BEGIN_defopt +Set this option to a callable which accepts two arguments, a record +instance and a mail instance. The callable should examine these +arguments and return the string name of a Gnus group to use for +looking up posting styles, or nil to use Gnus' defaults. +#+END_defopt + +When writing this function, functions such as ~ebdb-record-field~ and +~ebdb-record-current-fields~ may come in handy. Here's a less-obvious +example that dispatches styles depending on which database the record +belongs to: + +#+BEGIN_SRC elisp + (setq ebdb-gnus-post-style-function + (lambda (rec _mail) + (let ((dbs (slot-value (ebdb-record-cache rec) 'database))) + (if (object-assoc "File: work.dat" 'label dbs) + "nnimap+WorkAccount:INBOX" + "nnimap+PersonalAccount:INBOX")))) +#+END_SRC + +A current limitation of this functionality is that it only works when +composing a mail to a single recipient. If you mark several records +in a {{{buf(EBDB)}}} buffer and compose a mail to them collectively, +the mechanism will be bypassed. + * EBDB Buffers :PROPERTIES: :ID: 877ca77a-06d6-4fbf-87ec-614d03c37e30 diff --git a/ebdb.texi b/ebdb.texi index c5c5369..fbecee7 100644 --- a/ebdb.texi +++ b/ebdb.texi @@ -52,6 +52,7 @@ modify this GNU manual.” * Creating Records:: * Record Fields:: * MUA Interaction:: +* Specific MUAs:: * EBDB Buffers:: * Completion:: * Snarfing:: @@ -117,6 +118,15 @@ EBDB and MUA summary buffers * Summary buffer marks:: +Specific MUAs + +* Gnus:: + +Gnus + +* Posting Styles:: + + EBDB Buffers * Searching:: @@ -893,6 +903,59 @@ Format letter to use in the summary buffer format string to mark a record. Defaults to ``e''. @end defopt +@node Specific MUAs +@chapter Specific MUAs + +@menu +* Gnus:: +@end menu + +@node Gnus +@section Gnus + +EBDB has a little more support for Gnus than the other MUAs, for no +other reason than that Gnus is what the author uses. + +@menu +* Posting Styles:: +@end menu + +@node Posting Styles +@subsection Posting Styles + +Gnus provides a ``posting styles'' mechanism which allows the user to +set up specific mail composition styles (custom headers and +signatures, etc) when writing mails to certain recipients. The +mechanism examines Gnus group names to determine which styles to use. +EBDB can fake this mechanism so that different styles are used when +composing messages to different records. + +@defopt ebdb-gnus-post-style-function +Set this option to a callable which accepts two arguments, a record +instance and a mail instance. The callable should examine these +arguments and return the string name of a Gnus group to use for +looking up posting styles, or nil to use Gnus' defaults. +@end defopt + +When writing this function, functions such as @code{ebdb-record-field} and +@code{ebdb-record-current-fields} may come in handy. Here's a less-obvious +example that dispatches styles depending on which database the record +belongs to: + +@lisp +(setq ebdb-gnus-post-style-function + (lambda (rec _mail) + (let ((dbs (slot-value (ebdb-record-cache rec) 'database))) + (if (object-assoc "File: work.dat" 'label dbs) + "nnimap+WorkAccount:INBOX" + "nnimap+PersonalAccount:INBOX")))) +@end lisp + +A current limitation of this functionality is that it only works when +composing a mail to a single recipient. If you mark several records +in a *EBDB* buffer and compose a mail to them collectively, +the mechanism will be bypassed. + @node EBDB Buffers @chapter EBDB Buffers