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