]> git.pld-linux.org Git - packages/mutt.git/blob - mutt-xface.patch
- vvv.initials patch from mutt.org.ua
[packages/mutt.git] / mutt-xface.patch
1 x-face patch for Mutt 1.5.6
2
3 Copied from Debian's slrnface package:
4
5     http://dave.willfork.com/slrnface/
6     Upstream Author: Drazen Kacar <dave@arsdigita.com>
7     Copyright: /usr/share/common-licenses/GPL
8
9
10 --- mutt-1.4./README.xface      Thu Jan  1 01:00:00 1970
11 +++ mutt-1.4/README.xface       Sat Aug 24 02:29:23 2002
12 @@ -0,0 +1,80 @@
13 +This is slrnface, a small helper utility which displays X-Faces on behalf
14 +of programs like slrn and mutt when they are run in the X11 terminal
15 +emulator.
16 +
17 +Requirements:
18 +
19 +a) X11.
20 +b) Terminal emulator which sets WINDOWID environment variable. Most of the
21 +   ones in common use will set it. If you're using some terminal emulator
22 +   which doesn't have this capability, you'll have to set it yourself.
23 +
24 +How to build:
25 +
26 +a) Install libcompface. I recommend getting the source from the nearest
27 +   Debian GNU/Linux mirror because there's a patch which adds the
28 +   ability to output XBM image, as well as the historic brain dead
29 +   format. Slrnface doesn't use that feature, but it might be handy for
30 +   something else.
31 +
32 +b) Edit Makefile.
33 +
34 +c) Invoke make.
35 +
36 +d) Install with "make install".
37 +
38 +Upgrading from version 1.x:
39 +
40 +   If you have used one of the older versions of slrnface, you probably
41 +   have .slrnface file in your home directory. You can delete it, because
42 +   the new version doesn't use it any more. Instead, the pipes will be
43 +   created in $HOME/.slrnfaces directory. There are no other user visible
44 +   changes.
45 +
46 +Using slrnface with slrn:
47 +
48 +   This version requires S-Lang 1.4 or later and slrn 0.9.7.4. It might
49 +   work with slrn 0.9.7.3, but I haven't tested that configuration. It
50 +   will not work properly with older versions.
51 +
52 +   In case you can't or won't upgrade, take a look at the slrnface home
53 +   page. You'll find older versions which might work with what you have.
54 +
55 +   Take a look at slrnface.sl, edit if you want and then include it in
56 +   your .slrnrc, like this:
57 +
58 +   interpret slrnface.sl
59 +
60 +   Run slrn.
61 +
62 +Using slrnface with mutt:
63 +
64 +   Mutt doesn't have a way to use some kind of embeded interpreter, like
65 +   S-Lang. Since Mutt's current capabilities are not good enough for our
66 +   purposes, a patch for the source is provided. It has been tested with
67 +   mutt 1.4, but it should work with the 1.3.x series, if x is high
68 +   enough.
69 +
70 +   Uncompress mutt 1.4 source and apply mutt.patch from the slrnface
71 +   distribution.
72 +
73 +   Compile mutt as usual.
74 +
75 +   Edit your ~/.muttrc and add:
76 +
77 +   set xface=yes
78 +
79 +   Run mutt.
80 +
81 +If you think X-Faces are not placed at the appropriate location on your
82 +terminal emulator window or you don't like the colors, set some X resources.
83 +Read the man page for more information. Additional documentation is in the
84 +doc directory.
85 +
86 +Licence: GPL. See file called COPYING.
87 +
88 +Special thanks to Mark R. Bowyer for proofreading the man page.
89 +
90 +Home page: http://dave.willfork.com/slrnface/
91 +
92 +dave@willfork.com
93 diff -urp ../MUTT/mutt/PATCHES mutt/PATCHES
94 --- ../MUTT/mutt/PATCHES        2002-12-09 18:44:54.000000000 +0100
95 +++ mutt/PATCHES        2004-07-21 16:02:16.000000000 +0200
96 @@ -0,0 +1 @@
97 +patch-1.5.6.cb.xface.1
98 diff -urp ../MUTT/mutt/globals.h mutt/globals.h
99 --- ../MUTT/mutt/globals.h.orig 2007-03-26 14:49:03.226880430 +0200
100 +++ mutt/globals.h      2007-03-26 14:51:13.227945753 +0200
101 @@ -218,6 +218,8 @@
102  WHERE ALIAS *Aliases INITVAL (0);
103  WHERE LIST *UserHeader INITVAL (0);
104  
105 +WHERE int slrnface_fd INITVAL (-1);
106 +
107  /*-- formerly in pgp.h --*/
108  WHERE REGEXP PgpGoodSign;
109  WHERE char *PgpSignAs;
110 diff -urp ../MUTT/mutt/init.c mutt/init.c
111 --- ../MUTT/mutt/init.c 2004-07-18 01:25:28.000000000 +0200
112 +++ mutt/init.c 2004-07-21 13:33:47.000000000 +0200
113 @@ -43,6 +43,8 @@
114  #include <string.h>
115  #include <sys/utsname.h>
116  #include <errno.h>
117 +#include <sys/types.h>
118 +#include <fcntl.h>
119  #include <sys/wait.h>
120  
121  void toggle_quadoption (int opt)
122 @@ -2356,3 +2358,130 @@ int mutt_get_hook_type (const char *name
123    return 1;
124  }
125  
126 +void mutt_start_slrnface(void)
127 +{
128 +  char *fifo;
129 +  int pathlen, status;
130 +  pid_t pid, pidst;
131 +  struct utsname u;
132 +
133 +  if (!option(OPTXFACE))
134 +    return;
135 +
136 +  /*
137 +   * If we don't have display, there's no point. The user probably knows,
138 +   * so fail silently.
139 +   */
140 +  if (!getenv("DISPLAY"))
141 +    return;
142 +  /* If there is no WINDOWID, complain. */
143 +  if (!getenv ("WINDOWID"))
144 +  {
145 +    mutt_error (_("Cannot run slrnface: WINDOWID not found in environment."));
146 +    return;
147 +  }
148 +
149 +  uname (&u);
150 +  pathlen = strlen (Homedir) + sizeof("/.slrnfaces/")
151 +            + strlen (u.nodename) + 30;
152 +  fifo = safe_malloc (pathlen);
153 +  sprintf (fifo, "%s/.slrnfaces", Homedir);
154 +  if (mkdir (fifo, 0700))
155 +  {
156 +    if (errno != EEXIST)
157 +    {
158 +      mutt_error (_("Cannot run slrnface: failed to create %s: %s."),
159 +                 fifo, strerror(errno));
160 +      return;
161 +    }
162 +  }
163 +  else
164 +  {
165 +    FILE *fp;
166 +
167 +    /* We'll abuse fifo filename memory here. It's long enough. */
168 +    sprintf (fifo, "%s/.slrnfaces/README", Homedir);
169 +    if ((fp = fopen (fifo, "w")) != NULL)
170 +    {
171 +      fputs (_(
172 +"This directory is used to create named pipes for communication between\n"
173 +"slrnface and its parent process. It should normally be empty because\n"
174 +"the pipe is deleted right after it has been opened by both processes.\n\n"
175 +"File names generated by slrnface have the form \"hostname.pid\". It is\n"
176 +"probably an error if they linger here longer than a fraction of a second.\n\n"
177 +"However, if the directory is mounted from an NFS server, you might see\n"
178 +"special files created by your NFS server while slrnface is running.\n"
179 +"Do not try to remove them.\n"), fp);
180 +      fclose (fp);
181 +    }
182 +  }
183 +
184 +  status = snprintf (fifo, pathlen, "%s/.slrnfaces/%s.%ld", Homedir,
185 +                    u.nodename, (long)getpid());
186 +  if (status < 0)
187 +    goto clean_face;
188 +
189 +  unlink (fifo);
190 +  if (mkfifo (fifo, 0600) < 0)
191 +  {
192 +    mutt_error (_("Cannot run slrnface, failed to create %s: %s."), fifo,
193 +               strerror(errno));
194 +    goto clean_face;
195 +  }
196 +
197 +  pid = fork();
198 +  switch (pid)
199 +  {
200 +    case -1: break;
201 +    case 0:  execlp ("slrnface", "slrnface", fifo, (char *)0);
202 +            /* This is child, exit on error. */
203 +            _exit (10);
204 +    default: do {
205 +              pidst = waitpid (pid, &status, 0);
206 +            } while (pidst == -1 && errno == EINTR);
207 +
208 +            if (!WIFEXITED (status))
209 +              mutt_error (_("Slrnface abnormaly exited, code %d."), status);
210 +            else
211 +            {
212 +              char *message;
213 +
214 +              switch (WEXITSTATUS (status))
215 +              {
216 +                case 0: /* All fine, open the pipe */
217 +                        slrnface_fd = open (fifo, O_WRONLY, 0600);
218 +                        write (slrnface_fd, "start\n", sizeof "start");
219 +                        goto clean_face;
220 +                case 1: message = "couldn't connect to display";
221 +                        break;
222 +                case 2: message = "WINDOWID not found in environment";
223 +                        break;
224 +                case 3: message = "couldn't find controlling terminal";
225 +                        break;
226 +                case 4: message = "terminal doesn't export width and height";
227 +                        break;
228 +                case 5: message = "cannot open FIFO";
229 +                        break;
230 +                case 6: message = "fork() failed";
231 +                        break;
232 +                case 10: message = "executable not found";
233 +                         break;
234 +                default: message = "unknown error";
235 +              }
236 +              mutt_error (_("Slrnface failed: %s."), message);
237 +            }
238 +  }
239 +
240 +clean_face:
241 +  unlink (fifo);
242 +  free (fifo);
243 +}
244 +
245 +void mutt_stop_slrnface(void)
246 +{
247 +  if (slrnface_fd >= 0)
248 +    close(slrnface_fd);
249 +  slrnface_fd = -1;
250 +
251 +  /* FIFO has been unlinked in the startup function. */
252 +}
253 diff -urp ../MUTT/mutt/init.h mutt/init.h
254 --- ../MUTT/mutt/init.h 2004-07-21 13:33:02.000000000 +0200
255 +++ mutt/init.h 2004-07-21 13:33:47.000000000 +0200
256 @@ -2736,6 +2736,12 @@ struct option_t MuttVars[] = {
257    ** Controls whether mutt writes out the Bcc header when preparing
258    ** messages to be sent.  Exim users may wish to use this.
259    */
260 +  { "xface",           DT_BOOL, R_NONE, OPTXFACE, 0 },
261 +  /*
262 +  ** .pp
263 +  ** Controls whether mutt uses slrnface to display X-Faces when run
264 +  ** in an X11 terminal emulator.
265 +  */
266    /*--*/
267    { NULL }
268  };
269 diff -urp ../MUTT/mutt/main.c mutt/main.c
270 --- ../MUTT/mutt/main.c 2004-06-18 17:24:22.000000000 +0200
271 +++ mutt/main.c 2004-07-21 13:33:47.000000000 +0200
272 @@ -905,6 +905,8 @@ int main (int argc, char **argv)
273  
274      mutt_folder_hook (folder);
275  
276 +    mutt_start_slrnface();
277 +
278      if((Context = mx_open_mailbox (folder, ((flags & MUTT_RO) || option (OPTREADONLY)) ? MUTT_READONLY : 0, NULL))
279         || !explicit_folder)
280      {
281 @@ -913,6 +915,8 @@ int main (int argc, char **argv)
282      }
283  
284      exit_endwin_msg = Errorbuf;
285 +
286 +    mutt_stop_slrnface();
287    }
288  
289    exit_code = 0;
290 diff -urp ../MUTT/mutt/mutt.h mutt/mutt.h
291 --- ../MUTT/mutt/mutt.h 2004-07-21 13:33:02.000000000 +0200
292 +++ mutt/mutt.h 2004-07-21 13:33:47.000000000 +0200
293 @@ -435,6 +435,7 @@ enum
294    OPTWRAP,
295    OPTWRAPSEARCH,
296    OPTWRITEBCC,         /* write out a bcc header? */
297 +  OPTXFACE,
298    OPTXMAILER,
299  
300    OPTCRYPTUSEGPGME,
301 @@ -577,6 +578,7 @@ typedef struct envelope
302    BUFFER *spam;
303    LIST *references;            /* message references (in reverse order) */
304    LIST *in_reply_to;           /* in-reply-to header content */
305 +  LIST *x_face;                        /* X-Face header content */
306    LIST *userhdrs;              /* user defined headers */
307  } ENVELOPE;
308  
309 diff -urp ../MUTT/mutt/muttlib.c mutt/muttlib.c
310 --- ../MUTT/mutt/muttlib.c      2004-07-18 01:25:28.000000000 +0200
311 +++ mutt/muttlib.c      2004-07-21 13:33:47.000000000 +0200
312 @@ -651,6 +651,7 @@ void mutt_free_envelope (ENVELOPE **p)
313    FREE (&(*p)->date);
314    mutt_free_list (&(*p)->references);
315    mutt_free_list (&(*p)->in_reply_to);
316 +  mutt_free_list (&(*p)->x_face);
317    mutt_free_list (&(*p)->userhdrs);
318    FREE (p);
319  }
320 diff -urp ../MUTT/mutt/pager.c mutt/pager.c
321 --- ../MUTT/mutt/pager.c        2004-07-18 01:25:28.000000000 +0200
322 +++ mutt/pager.c        2004-07-21 13:36:34.000000000 +0200
323 @@ -1527,6 +1527,66 @@ upNLines (int nlines, struct line_t *inf
324    return cur;
325  }
326  
327 +static void
328 +mutt_display_xface (HEADER *hdr)
329 +{
330 +  LIST *face;
331 +  char buf[2000];
332 +
333 +  if (slrnface_fd < 0)
334 +    return;
335 +
336 +  if (!hdr)
337 +    return;
338 +
339 +  face = hdr->env->x_face;
340 +
341 +  if (face == NULL || face->data == NULL)
342 +    write(slrnface_fd, "clear\n", sizeof "clear");
343 +  else
344 +    do {
345 +      int len;
346 +
347 +      len = snprintf (buf, sizeof (buf), "xface %s\n", face->data);
348 +      if (len <= sizeof (buf))
349 +      {
350 +       write (slrnface_fd, buf, len);
351 +       break;
352 +      }
353 +      /*
354 +       * slrnface will ignore X-Faces larger than approx. 2000 chars, so
355 +       * try the next one, if it exists.
356 +       */
357 +    } while (face = face->next);
358 +}
359 +
360 +static void
361 +mutt_clear_xface (void)
362 +{
363 +  if (slrnface_fd < 0)
364 +    return;
365 +
366 +  write(slrnface_fd, "clear\n", sizeof "clear");
367 +}
368 +
369 +static void
370 +mutt_suppress_xface (void)
371 +{
372 +  if (slrnface_fd < 0)
373 +    return;
374 +
375 +  write(slrnface_fd, "suppress\n", sizeof "suppress");
376 +}
377 +
378 +static void
379 +mutt_show_xface (void)
380 +{
381 +  if (slrnface_fd < 0)
382 +    return;
383 +
384 +  write(slrnface_fd, "show\n", sizeof "show");
385 +}
386 +
387  static const struct mapping_t PagerHelp[] = {
388    { N_("Exit"),        OP_EXIT },
389    { N_("PrevPg"), OP_PREV_PAGE },
390 @@ -1545,6 +1605,9 @@ mutt_pager (const char *banner, const ch
391      snprintf (helpstr, sizeof (helpstr), "%s %s", tmphelp, buffer);
392    }
393  
394 +  if (IsHeader (extra))
395 +    mutt_display_xface(extra->hdr);
396 +
397    while (ch != -1)
398    {
399      mutt_curs_set (0);
400 @@ -2067,7 +2130,9 @@ search_next:
401         if (! InHelp)
402         {
403           InHelp = 1;
404 +         mutt_suppress_xface ();
405           mutt_help (MENU_PAGER);
406 +         mutt_show_xface ();
407           pager_menu->redraw = REDRAW_FULL;
408           InHelp = 0;
409         }
410 @@ -2383,58 +2448,70 @@ CHECK_IMAP_ACL(IMAP_ACL_WRITE);
411        case OP_MAIL:
412         CHECK_MODE(IsHeader (extra) && !IsAttach (extra));
413          CHECK_ATTACH;      
414 +       mutt_suppress_xface ();
415         ci_send_message (0, NULL, NULL, extra->ctx, NULL);
416 +       mutt_show_xface ();
417         pager_menu->redraw = REDRAW_FULL;
418         break;
419  
420        case OP_REPLY:
421         CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
422          CHECK_ATTACH;      
423 +       mutt_suppress_xface();
424          if (IsMsgAttach (extra)) 
425           mutt_attach_reply (extra->fp, extra->hdr, extra->actx,
426                              extra->bdy, SENDREPLY);
427         else
428           ci_send_message (SENDREPLY, NULL, NULL, extra->ctx, extra->hdr);
429 +       mutt_show_xface ();
430         pager_menu->redraw = REDRAW_FULL;
431         break;
432  
433        case OP_RECALL_MESSAGE:
434         CHECK_MODE(IsHeader (extra) && !IsAttach(extra));
435          CHECK_ATTACH;
436 +       mutt_suppress_xface();
437         ci_send_message (SENDPOSTPONED, NULL, NULL, extra->ctx, extra->hdr);
438 +       mutt_show_xface ();
439         pager_menu->redraw = REDRAW_FULL;
440         break;
441  
442        case OP_GROUP_REPLY:
443         CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
444          CHECK_ATTACH;
445 +       mutt_suppress_xface();
446          if (IsMsgAttach (extra))
447           mutt_attach_reply (extra->fp, extra->hdr, extra->actx,
448                              extra->bdy, SENDREPLY|SENDGROUPREPLY);
449          else
450           ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, extra->ctx, extra->hdr);
451 +       mutt_suppress_xface ();
452         pager_menu->redraw = REDRAW_FULL;
453         break;
454  
455        case OP_LIST_REPLY:
456         CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
457          CHECK_ATTACH;        
458 +       mutt_suppress_xface();
459          if (IsMsgAttach (extra))
460           mutt_attach_reply (extra->fp, extra->hdr, extra->actx,
461                              extra->bdy, SENDREPLY|SENDLISTREPLY);
462          else
463           ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, extra->ctx, extra->hdr);
464 +       mutt_show_xface ();
465         pager_menu->redraw = REDRAW_FULL;
466         break;
467  
468        case OP_FORWARD_MESSAGE:
469         CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
470          CHECK_ATTACH;
471 +       mutt_suppress_xface();
472          if (IsMsgAttach (extra))
473           mutt_attach_forward (extra->fp, extra->hdr, extra->actx,
474                                extra->bdy);
475          else
476           ci_send_message (SENDFORWARD, NULL, NULL, extra->ctx, extra->hdr);
477 +       mutt_show_xface ();
478         pager_menu->redraw = REDRAW_FULL;
479         break;
480  
481 @@ -2485,7 +2562,9 @@ CHECK_IMAP_ACL(IMAP_ACL_WRITE);
482         break;
483  
484        case OP_SHELL_ESCAPE:
485 +       mutt_suppress_xface ();
486         mutt_shell_escape ();
487 +       mutt_show_xface ();
488         break;
489  
490        case OP_TAG:
491 @@ -2644,5 +2723,6 @@ CHECK_IMAP_ACL(IMAP_ACL_DELETE);
492    FREE (&rd.pager_status_window);
493    FREE (&rd.pager_window);
494  
495 +  mutt_clear_xface ();
496    return (rc != -1 ? rc : 0);
497  }
498 diff -urp ../MUTT/mutt/parse.c mutt/parse.c
499 --- ../MUTT/mutt/parse.c        2004-07-21 13:33:02.000000000 +0200
500 +++ mutt/parse.c        2004-07-21 13:33:47.000000000 +0200
501 @@ -85,6 +85,27 @@ static char *read_rfc822_line (FILE *f, 
502    /* not reached */
503  }
504  
505 +static LIST *mutt_add_x_face (LIST *lst, char *face)
506 +{
507 +  LIST *n;
508 +
509 +  n = safe_malloc(sizeof(LIST));
510 +  n->data = safe_strdup(face);
511 +  n->next = NULL;
512 +
513 +  if (lst)
514 +  {
515 +    LIST *l;
516 +
517 +    for(l = lst; l->next; l = l->next);
518 +    l->next = n;
519 +  }
520 +  else
521 +    lst = n;
522 +
523 +  return lst;
524 +}
525 +
526  static LIST *mutt_parse_references (char *s, int in_reply_to)
527  {
528    LIST *t, *lst = NULL;
529 @@ -1231,6 +1252,11 @@ int mutt_parse_rfc822_line (ENVELOPE *e,
530        e->x_label = safe_strdup(p);
531        matched = 1;
532      }
533 +    else if (ascii_strcasecmp (line+1, "-face") == 0)
534 +    {
535 +      e->x_face = mutt_add_x_face (e->x_face, p);
536 +      matched = 1;
537 +    }
538      
539      default:
540      break;
541 diff -urp ../MUTT/mutt/sendlib.c mutt/sendlib.c
542 --- ../MUTT/mutt/sendlib.c      2004-07-21 13:33:02.000000000 +0200
543 +++ mutt/sendlib.c      2004-07-21 13:37:16.000000000 +0200
544 @@ -1697,6 +1697,15 @@ int mutt_write_rfc822_header (FILE *fp, 
545      }
546    }
547  
548 +  /* Add X-Face headers */
549 +  if (env->x_face)
550 +  {
551 +    LIST *face;
552 +
553 +    for (face = env->x_face; face; face = face->next)
554 +      fprintf (fp, "X-Face: %s\n", face->data);
555 +  }
556 +
557    if (mode == 0 && !privacy && option (OPTXMAILER) && !has_agent)
558    {
559      /* Add a vanity header */
This page took 0.103241 seconds and 3 git commands to generate.