Evtloop fixes.
[apps/madmutt.git] / alias.cpkg
index 424adda..4530db9 100644 (file)
 
 #include <lib-sys/unix.h>
 
-#include <lib-ui/curses.h>
-#include <lib-ui/enter.h>
+#include <lib-ui/lib-ui.h>
 #include <lib-ui/menu.h>
 
 #include "alias.h"
 #include "mutt_idna.h"
 #include "sort.h"
-
-@type bool = {
-    .kind = 'b';
-    .ctype = unsigned : 1;
-};
-
-@type string_t = {
-    .kind  = 's';
-    .ctype = char *;
-    .dtor  = p_delete($$);
-    .ctor  = m_strdup($$);
-};
-
-@type path_t = {
-    .push  = luaM_path_post($$);
-    .kind  = 's';
-    .ctype = char *;
-    .dtor  = p_delete($$);
-    .ctor  = m_strdup($$);
+@import  "lib-lua/base.cpkg"
+
+static rx_t *Alternates = NULL, *UnAlternates = NULL;
+rx_t *MailLists = NULL, *UnMailLists = NULL;
+rx_t *SubscribedLists = NULL, *UnSubscribedLists = NULL;
+
+@package MAlias {
+    /*
+     ** .pp
+     ** Specifies the format of the data displayed for the ``alias'' menu. The
+     ** following \fTprintf(3)\fP-style sequences are available:
+     ** .pp
+     ** .dl
+     ** .dt %a .dd alias name
+     ** .dt %f .dd flags - currently, a "d" for an alias marked for deletion
+     ** .dt %n .dd index number
+     ** .dt %r .dd address which alias expands to
+     ** .dt %t .dd character which indicates if the alias is tagged for inclusion
+     ** .de
+     */
+    string_t alias_format = m_strdup("%4n %2f %t %-10a   %r");
+    /*
+     ** .pp
+     ** The default file in which to save aliases created by the
+     ** ``$create-alias'' function.
+     ** .pp
+     ** \fBNote:\fP Madmutt will not automatically source this file; you must
+     ** explicitly use the ``$source'' command for it to be executed.
+     */
+    path_t alias_file = m_strdup("~/.madmutt/aliases");
+
+    /*
+     ** .pp
+     ** Specifies the filename of your signature, which is appended to all
+     ** outgoing messages.   If the filename ends with a pipe (``\fT|\fP''), it is
+     ** assumed that filename is a shell command and input should be read from
+     ** its stdout.
+     */
+    path_t signature = m_strdup("~/.signature");
+
+    /*
+     ** .pp
+     ** This specifies the file into which your outgoing messages should be
+     ** appended.  (This is meant as the primary method for saving a copy of
+     ** your messages, but another way to do this is using the ``$my_hdr''
+     ** command to create a \fTBcc:\fP header field with your email address in it.)
+     ** .pp
+     ** The value of \fI$$record\fP is overridden by the ``$$force_name'' and
+     ** ``$$save_name'' variables, and the ``$fcc-hook'' command.
+     */
+    path_t record = NULL;
+
+    /*
+     ** .pp
+     ** This variable contains a default from address.  It
+     ** can be overridden using my_hdr (including from send-hooks) and
+     ** ``$$reverse_name''.  This variable is ignored if ``$$use_from''
+     ** is unset.
+     ** .pp
+     ** E.g. you can use
+     ** \fTsend-hook Madmutt-devel@lists.berlios.de 'my_hdr From: Foo Bar <foo@bar.fb>'\fP
+     ** when replying to the Madmutt developer's mailing list and Madmutt takes this email address.
+     ** .pp
+     ** Defaults to the contents of the environment variable \fT$$$EMAIL\fP.
+     */
+    address_t from = rfc822_parse_adrlist(NULL, NONULL(getenv("EMAIL")));
+
+    void alternates(rx_t rx) {
+        rx_list_remove(&UnAlternates, rx);
+        rx_list_add(&Alternates, rx);
+        RETURN();
+    };
+    void unalternates(rx_t rx) {
+        rx_list_remove(&Alternates, rx);
+        rx_list_add(&UnAlternates, rx);
+        RETURN();
+    };
+
+    void lists(rx_t rx) {
+        rx_list_remove(&UnMailLists, rx);
+        rx_list_add(&MailLists, rx);
+        RETURN();
+    };
+    void unlists(rx_t rx) {
+        rx_list_remove(&MailLists, rx);
+        rx_list_remove(&SubscribedLists, rx);
+        rx_list_add(&UnMailLists, rx);
+        RETURN();
+    };
+
+    void subscribe(rx_t rx) {
+        rx_list_remove(&UnMailLists, rx);
+        rx_list_remove(&UnSubscribedLists, rx);
+        rx_list_add(&MailLists, rx);
+        rx_list_add(&SubscribedLists, rx_dup(rx));
+        RETURN();
+    };
+    void unsubscribe(rx_t rx) {
+        rx_list_remove(&SubscribedLists, rx);
+        rx_list_add(&UnSubscribedLists, rx);
+        RETURN();
+    };
 };
 
-@type quadopt_t = {
-    .kind  = 'i';
-    .check = luaM_checkquadopt($L, $$);
-    .ctype = unsigned : 2;
-};
-
-static @package MAlias {
-    path_t alias_format = m_strdup("%4n %2f %t %-10a   %r");
-} MAlias;
-
-char    *AliasFile;
 alias_t *Aliases;
-rx_t     GecosMask;
 
 #define RSORT(x) (SortAlias & SORT_REVERSE) ? -x : x
 
-static struct mapping_t AliasHelp[] = {
-    {N_("Exit"), OP_EXIT},
-    {N_("Del"), OP_DELETE},
-    {N_("Undel"), OP_UNDELETE},
-    {N_("Select"), OP_GENERIC_SELECT_ENTRY},
-    {N_("Help"), OP_HELP},
-    {NULL, OP_NULL}
-};
-
 static void mutt_alias_menu(char *, size_t, alias_t *);
 
 const address_t *alias_lookup(const char *s)
@@ -136,11 +197,11 @@ int mutt_addr_is_user(address_t *addr)
     if (!addr->mailbox)
         return 0;
 
-    if (!ascii_strcasecmp(addr->mailbox, MCore.username)
-    ||  string_is_address(addr->mailbox, MCore.username, Hostname)
-    ||  string_is_address(addr->mailbox, MCore.username, mutt_fqdn(0))
-    ||  string_is_address(addr->mailbox, MCore.username, mutt_fqdn(1))
-    ||  (From && !ascii_strcasecmp(From->mailbox, addr->mailbox)))
+    if (!ascii_strcasecmp(addr->mailbox, mod_core.username)
+    ||  string_is_address(addr->mailbox, mod_core.username, mod_core.shorthost)
+    ||  string_is_address(addr->mailbox, mod_core.username, mutt_fqdn(0))
+    ||  string_is_address(addr->mailbox, mod_core.username, mutt_fqdn(1))
+    ||  (MAlias.from && !ascii_strcasecmp(MAlias.from->mailbox, addr->mailbox)))
     {
         return 1;
     }
@@ -311,7 +372,7 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr)
 
     alias_list_push(&Aliases, new);
 
-    m_strcpy(buf, sizeof(buf), NONULL(AliasFile));
+    m_strcpy(buf, sizeof(buf), NONULL(MAlias.alias_file));
     if (mutt_get_field(_("Save to file: "), buf, sizeof(buf), M_FILE)) {
         return;
     }
@@ -374,7 +435,7 @@ static address_t *mutt_expand_aliases_r(address_t *a, string_list_t **expn)
 
                 if (pw) {
                     char namebuf[STRING];
-                    mutt_gecos_name(namebuf, sizeof(namebuf), pw, GecosMask.rx);
+                    mutt_gecos_name(namebuf, sizeof(namebuf), pw, mod_core.gecos_mask);
                     m_strreplace(&pop->personal, namebuf);
                 }
             }
@@ -383,7 +444,7 @@ static address_t *mutt_expand_aliases_r(address_t *a, string_list_t **expn)
         last = address_list_append(last, pop);
     }
 
-    if (option(OPTUSEDOMAIN)) {
+    if (mod_core.use_domain) {
         /* now qualify all local addresses */
         rfc822_qualify(head, mutt_fqdn(1));
     }
@@ -545,9 +606,8 @@ alias_format_str(char *dest, ssize_t destlen, char op, const char *src,
 
 static void alias_entry(char *s, ssize_t slen, MUTTMENU *m, int num)
 {
-    m_strformat(s, slen, COLS - SW, MAlias.alias_format, alias_format_str,
-                ((alias_t **)m->data)[num],
-                option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0);
+    m_strformat(s, slen, getmaxx(main_w), MAlias.alias_format, alias_format_str,
+                ((alias_t **)m->data)[num], 0);
 }
 
 static int alias_tag (MUTTMENU * menu, int n, int m)
@@ -566,7 +626,7 @@ static int alias_SortAlias (const void *a, const void *b)
   alias_t *pb = *(alias_t **) b;
   int r = m_strcasecmp(pa->name, pb->name);
 
-  return (RSORT (r));
+  return RSORT (r);
 }
 
 static int alias_SortAddress (const void *a, const void *b)
@@ -591,7 +651,7 @@ static int alias_SortAddress (const void *a, const void *b)
     r = -1;
   else
     r = ascii_strcasecmp (pa->mailbox, pb->mailbox);
-  return (RSORT (r));
+  return RSORT (r);
 }
 
 void mutt_alias_menu (char *buf, size_t buflen, alias_t * aliases)
@@ -602,7 +662,6 @@ void mutt_alias_menu (char *buf, size_t buflen, alias_t * aliases)
   int t = -1;
   int i, done = 0;
   int op;
-  char helpstr[STRING];
 
   int omax;
 
@@ -620,8 +679,6 @@ void mutt_alias_menu (char *buf, size_t buflen, alias_t * aliases)
   menu->tag = alias_tag;
   menu->menu = MENU_ALIAS;
   menu->title = _("Aliases");
-  menu->help = mutt_compile_help(helpstr, sizeof(helpstr),
-                                 MENU_ALIAS, AliasHelp);
 
 new_aliases: