a36b2c74234bfef0f2c54e1580219d55dd664474
[mmh] / uip / repl.c
1 /*
2 ** repl.c -- reply to a message
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 */
8
9 #include <h/mh.h>
10 #include <h/utils.h>
11 #include <h/addrsbr.h>
12 #include <h/fmt_scan.h>
13 #include <sys/file.h>  /* L_SET */
14 #include <errno.h>
15
16
17 static struct swit switches[] = {
18 #define GROUPSW  0
19         { "group", 0 },
20 #define NGROUPSW  1
21         { "nogroup", 0 },
22 #define ANNOSW  2
23         { "annotate", 0 },
24 #define NANNOSW  3
25         { "noannotate", 0 },
26 #define CCSW  4
27         { "cc all|to|cc|me", 0 },
28 #define NCCSW  5
29         { "nocc type", 0 },
30 #define EDITRSW  6
31         { "editor editor", 0 },
32 #define NEDITSW  7
33         { "noedit", 0 },
34 #define FILTSW  8
35         { "filter filterfile", 0 },
36 #define FORMSW  9
37         { "form formfile", 0 },
38 #define FRMTSW  10
39         { "format", 5 },
40 #define NFRMTSW  11
41         { "noformat", 7 },
42 #define MIMESW  12
43         { "mime", 0 },
44 #define NMIMESW  13
45         { "nomime", 0 },
46 #define QURYSW  14
47         { "query", 0 },
48 #define NQURYSW  15
49         { "noquery", 0 },
50 #define WHATSW  16
51         { "whatnowproc program", 0 },
52 #define NWHATSW  17
53         { "nowhatnowproc", 0 },
54 #define VERSIONSW  18
55         { "version", 0 },
56 #define HELPSW  19
57         { "help", 0 },
58 #define FILESW  20
59         { "file file", 4 },  /* interface from msh */
60
61 #ifdef MHE
62 #define BILDSW  21
63         { "build", 5 },  /* interface from mhe */
64 #endif
65
66         { NULL, 0 }
67 };
68
69 static struct swit ccswitches[] = {
70 #define CTOSW  0
71         { "to", 0 },
72 #define CCCSW  1
73         { "cc", 0 },
74 #define CMESW  2
75         { "me", 0 },
76 #define CALSW  3
77         { "all", 0 },
78         { NULL, 0 }
79 };
80
81 /*
82 ** Buffer size for content part of header fields.
83 ** We want this to be large enough so that we don't
84 ** do a lot of extra FLDPLUS calls on m_getfld but
85 ** small enough so that we don't snarf the entire
86 ** message body when we're not going to use any of it.
87 */
88 #define SBUFSIZ 256
89
90 static short ccto = -1;
91 static short cccc = -1;
92 static short ccme = -1;
93 static short querysw = 0;
94
95 static short groupreply = 0;  /* Is this a group reply? */
96
97 static int mime = 0;  /* include original as MIME part */
98 static char *form   = NULL;  /* form (components) file */
99 static char *filter = NULL;  /* message filter file */
100
101 static int dftype=0;
102
103 static char *badaddrs = NULL;
104 static char *dfhost = NULL;
105
106 static struct mailname mq = { NULL };
107
108 static struct format *fmt;
109
110 static int ncomps = 0;  /* # of interesting components */
111 static char **compbuffers = NULL;  /* buffers for component text */
112 static struct comp **used_buf = NULL;  /* stack for comp that use buffers */
113
114 static int dat[5];  /* aux. data for format routine */
115
116 static char *addrcomps[] = {
117         "from",
118         "sender",
119         "reply-to",
120         "to",
121         "cc",
122         "bcc",
123         "resent-from",
124         "resent-sender",
125         "resent-reply-to",
126         "resent-to",
127         "resent-cc",
128         "resent-bcc",
129         NULL
130 };
131
132 /*
133 ** static prototypes
134 */
135 static void docc(char *, int);
136 static int insert(struct mailname *);
137 static void replfilter(FILE *, FILE *, char *);
138 static void replout(FILE *, char *, char *, struct msgs *, int,
139                 char *, char *);
140
141
142 int
143 main(int argc, char **argv)
144 {
145         int anot = 0;
146         int nedit = 0, nwhat = 0;
147         char *cp, *cwd, *maildir, *file = NULL;
148         char *folder = NULL, *msg = NULL;
149         char *ed = NULL, drft[BUFSIZ], buf[BUFSIZ];
150         char **argp, **arguments;
151         struct msgs *mp = NULL;
152         FILE *in;
153
154 #ifdef MHE
155         int buildsw = 0;
156 #endif /* MHE */
157
158 #ifdef LOCALE
159         setlocale(LC_ALL, "");
160 #endif
161         invo_name = mhbasename(argv[0]);
162
163         /* read user profile/context */
164         context_read();
165
166         arguments = getarguments(invo_name, argc, argv, 1);
167         argp = arguments;
168
169         while ((cp = *argp++)) {
170                 if (*cp == '-') {
171                         switch (smatch(++cp, switches)) {
172                         case AMBIGSW:
173                                 ambigsw(cp, switches);
174                                 done(1);
175                         case UNKWNSW:
176                                 adios(NULL, "-%s unknown", cp);
177
178                         case HELPSW:
179                                 snprintf(buf, sizeof(buf), "%s: [+folder] [msg] [switches]", invo_name);
180                                 print_help(buf, switches, 1);
181                                 done(0);
182                         case VERSIONSW:
183                                 print_version(invo_name);
184                                 done(1);
185
186                         case GROUPSW:
187                                 groupreply++;
188                                 continue;
189                         case NGROUPSW:
190                                 groupreply = 0;
191                                 continue;
192
193                         case ANNOSW:
194                                 anot++;
195                                 continue;
196                         case NANNOSW:
197                                 anot = 0;
198                                 continue;
199
200                         case CCSW:
201                                 if (!(cp = *argp++) || *cp == '-')
202                                         adios(NULL, "missing argument to %s",
203                                                         argp[-2]);
204                                 docc(cp, 1);
205                                 continue;
206                         case NCCSW:
207                                 if (!(cp = *argp++) || *cp == '-')
208                                         adios(NULL, "missing argument to %s",
209                                                         argp[-2]);
210                                 docc(cp, 0);
211                                 continue;
212
213                         case EDITRSW:
214                                 if (!(ed = *argp++) || *ed == '-')
215                                         adios(NULL, "missing argument to %s",
216                                                         argp[-2]);
217                                 nedit = 0;
218                                 continue;
219                         case NEDITSW:
220                                 nedit++;
221                                 continue;
222
223                         case WHATSW:
224                                 if (!(whatnowproc = *argp++) ||
225                                                 *whatnowproc == '-')
226                                         adios(NULL, "missing argument to %s",
227                                                         argp[-2]);
228                                 nwhat = 0;
229                                 continue;
230 #ifdef MHE
231                         case BILDSW:
232                                 buildsw++;  /* fall... */
233 #endif /* MHE */
234                         case NWHATSW:
235                                 nwhat++;
236                                 continue;
237
238                         case FILESW:
239                                 if (file)
240                                         adios(NULL, "only one file at a time!");
241                                 if (!(cp = *argp++) || *cp == '-')
242                                         adios(NULL, "missing argument to %s",
243                                                         argp[-2]);
244                                 file = getcpy(expanddir(cp));
245                                 continue;
246                         case FILTSW:
247                                 if (!(cp = *argp++) || *cp == '-')
248                                         adios(NULL, "missing argument to %s",
249                                                         argp[-2]);
250                                 filter = getcpy(etcpath(cp));
251                                 mime = 0;
252                                 continue;
253                         case FORMSW:
254                                 if (!(form = *argp++) || *form == '-')
255                                         adios(NULL, "missing argument to %s",
256                                                         argp[-2]);
257                                 continue;
258
259                         case FRMTSW:
260                                 filter = getcpy(etcpath(mhlreply));
261                                 mime = 0;
262                                 continue;
263                         case NFRMTSW:
264                                 filter = NULL;
265                                 continue;
266
267                         case MIMESW:
268                                 mime++;
269                                 filter = NULL;
270                                 continue;
271                         case NMIMESW:
272                                 mime = 0;
273                                 continue;
274
275                         case QURYSW:
276                                 querysw++;
277                                 continue;
278                         case NQURYSW:
279                                 querysw = 0;
280                                 continue;
281
282                         }
283                 }
284                 if (*cp == '+' || *cp == '@') {
285                         if (folder)
286                                 adios(NULL, "only one folder at a time!");
287                         else
288                                 folder = getcpy(expandfol(cp));
289                 } else {
290                         if (msg)
291                                 adios(NULL, "only one message at a time!");
292                         else
293                                 msg = cp;
294                 }
295         }
296
297         if (ccto == -1)
298                 ccto = groupreply;
299         if (cccc == -1)
300                 cccc = groupreply;
301         if (ccme == -1)
302                 ccme = groupreply;
303
304         cwd = getcpy(pwd());
305
306         if (file && (msg || folder))
307                 adios(NULL, "can't mix files and folders/msgs");
308
309 #ifdef MHE
310         strncpy(drft, buildsw ? toabsdir("reply")
311                 : m_draft(seq_beyond), sizeof(drft));
312 #else
313         strncpy(drft, m_draft(seq_beyond), sizeof(drft));
314 #endif /* MHE */
315
316         if (file) {
317                 /*
318                 ** We are replying to a file.
319                 */
320                 anot = 0;  /* we don't want to annotate a file */
321         } else {
322                 /*
323                 ** We are replying to a message.
324                 */
325                 if (!msg)
326                         msg = seq_cur;
327                 if (!folder)
328                         folder = getcurfol();
329                 maildir = toabsdir(folder);
330
331                 if (chdir(maildir) == NOTOK)
332                         adios(maildir, "unable to change directory to");
333
334                 /* read folder and create message structure */
335                 if (!(mp = folder_read(folder)))
336                         adios(NULL, "unable to read folder %s", folder);
337
338                 /* check for empty folder */
339                 if (mp->nummsg == 0)
340                         adios(NULL, "no messages in %s", folder);
341
342                 /* parse the message range/sequence/name and set SELECTED */
343                 if (!m_convert(mp, msg))
344                         done(1);
345                 seq_setprev(mp);  /* set the previous-sequence */
346
347                 if (mp->numsel > 1)
348                         adios(NULL, "only one message at a time!");
349
350                 context_replace(curfolder, folder); /* update current folder */
351                 seq_setcur(mp, mp->lowsel);  /* update current message  */
352                 seq_save(mp);  /* synchronize sequences   */
353                 context_save();  /* save the context file   */
354         }
355
356         msg = file ? file : getcpy(m_name(mp->lowsel));
357
358         if ((in = fopen(msg, "r")) == NULL)
359                 adios(msg, "unable to open");
360
361         /* find form (components) file */
362         if (!form) {
363                 if (groupreply)
364                         form = etcpath(replgroupcomps);
365                 else
366                         form = etcpath(replcomps);
367         }
368
369         replout(in, msg, drft, mp, mime, form, filter);
370         fclose(in);
371
372         if (nwhat)
373                 done(0);
374         what_now(ed, nedit, NOUSE, drft, msg, 0, mp, anot ? "Replied" : NULL,
375                         cwd);
376         done(1);
377         return 1;
378 }
379
380 static void
381 docc(char *cp, int ccflag)
382 {
383         switch (smatch(cp, ccswitches)) {
384         case AMBIGSW:
385                 ambigsw(cp, ccswitches);
386                 done(1);
387         case UNKWNSW:
388                 adios(NULL, "-%scc %s unknown", ccflag ? "" : "no", cp);
389
390         case CTOSW:
391                 ccto = ccflag;
392                 break;
393
394         case CCCSW:
395                 cccc = ccflag;
396                 break;
397
398         case CMESW:
399                 ccme = ccflag;
400                 break;
401
402         case CALSW:
403                 ccto = cccc = ccme = ccflag;
404                 break;
405         }
406 }
407
408
409
410
411 static void
412 replout(FILE *inb, char *msg, char *drft, struct msgs *mp,
413         int mime, char *form, char *filter)
414 {
415         register int state, i;
416         register struct comp *cptr;
417         register char *tmpbuf;
418         register char **nxtbuf;
419         register char **ap;
420         register struct comp **savecomp;
421         int char_read = 0, format_len, mask;
422         char name[NAMESZ], *scanl;
423         unsigned char *cp;
424         FILE *out;
425
426         mask = umask(~m_gmprot());
427         if ((out = fopen(drft, "w")) == NULL)
428                 adios(drft, "unable to create");
429
430         umask(mask);
431
432         /* get new format string */
433         cp = new_fs(form, NULL, NULL);
434         format_len = strlen(cp);
435
436         /* compile format string */
437         ncomps = fmt_compile(cp, &fmt) + 1;
438
439         if (!(nxtbuf = compbuffers = (char **)
440                         calloc((size_t) ncomps, sizeof(char *))))
441                 adios(NULL, "unable to allocate component buffers");
442         if (!(savecomp = used_buf = (struct comp **)
443                         calloc((size_t) (ncomps+1), sizeof(struct comp *))))
444                 adios(NULL, "unable to allocate component buffer stack");
445         savecomp += ncomps + 1;
446         *--savecomp = NULL;  /* point at zero'd end minus 1 */
447
448         for (i = ncomps; i--; )
449                 *nxtbuf++ = mh_xmalloc(SBUFSIZ);
450
451         nxtbuf = compbuffers;  /* point at start */
452         tmpbuf = *nxtbuf++;
453
454         for (ap = addrcomps; *ap; ap++) {
455                 FINDCOMP(cptr, *ap);
456                 if (cptr)
457                         cptr->c_type |= CT_ADDR;
458         }
459
460         /*
461         ** ignore any components killed by command line switches
462         */
463         if (!ccto) {
464                 FINDCOMP(cptr, "to");
465                 if (cptr)
466                         cptr->c_name = "";
467         }
468         if (!cccc) {
469                 FINDCOMP(cptr, "cc");
470                 if (cptr)
471                         cptr->c_name = "";
472         }
473         if ((cp = getenv("USER"))) {
474                 FINDCOMP(cptr, "user");
475                 if (cptr)
476                         cptr->c_text = getcpy(cp);
477         }
478         if (!ccme)
479                 ismymbox(NULL);
480
481         /*
482         ** pick any interesting stuff out of msg "inb"
483         */
484         for (state = FLD;;) {
485                 state = m_getfld(state, name, tmpbuf, SBUFSIZ, inb);
486                 switch (state) {
487                 case FLD:
488                 case FLDPLUS:
489                         /*
490                         ** if we're interested in this component, save
491                         ** a pointer to the component text, then start
492                         ** using our next free buffer as the component
493                         ** temp buffer (buffer switching saves an extra
494                         ** copy of the component text).
495                         */
496                         if ((cptr = wantcomp[CHASH(name)]))
497                                 do {
498                                         if (!mh_strcasecmp(name, cptr->c_name)) {
499                                                 char_read += msg_count;
500                                                 if (! cptr->c_text) {
501                                                         i = strlen(cptr->c_text = tmpbuf) - 1;
502                                                         if (tmpbuf[i] == '\n')
503                                                                 tmpbuf[i] = '\0';
504                                                         *--savecomp = cptr;
505                                                         tmpbuf = *nxtbuf++;
506                                                 } else {
507                                                         i = strlen(cp = cptr->c_text) - 1;
508                                                         if (cp[i] == '\n') {
509                                                                 if (cptr->c_type & CT_ADDR) {
510                                                                         cp[i] = '\0';
511                                                                         cp = add(",\n\t", cp);
512                                                                 } else {
513                                                                         cp = add("\t", cp);
514                                                                 }
515                                                         }
516                                                         cptr->c_text = add(tmpbuf, cp);
517                                                 }
518                                                 while (state == FLDPLUS) {
519                                                         state = m_getfld(state, name, tmpbuf,
520                                                                                           SBUFSIZ, inb);
521                                                         cptr->c_text = add(tmpbuf, cptr->c_text);
522                                                         char_read += msg_count;
523                                                 }
524                                                 break;
525                                         }
526                                 } while ((cptr = cptr->c_next));
527
528                         while (state == FLDPLUS)
529                                 state = m_getfld(state, name, tmpbuf,
530                                                 SBUFSIZ, inb);
531                         break;
532
533                 case LENERR:
534                 case FMTERR:
535                 case BODY:
536                 case FILEEOF:
537                         goto finished;
538
539                 default:
540                         adios(NULL, "m_getfld() returned %d", state);
541                 }
542         }
543
544         /*
545         ** format and output the header lines.
546         */
547 finished:
548
549         /*
550         ** if there's a "Subject" component, strip any "Re:"s off it
551         */
552         FINDCOMP(cptr, "subject")
553         if (cptr && (cp = cptr->c_text)) {
554                 register char *sp = cp;
555
556                 for (;;) {
557                         while (isspace(*cp))
558                                 cp++;
559                         if(uprf(cp, "re:"))
560                                 cp += 3;
561                         else
562                                 break;
563                         sp = cp;
564                 }
565                 if (sp != cptr->c_text) {
566                         cp = cptr->c_text;
567                         cptr->c_text = getcpy(sp);
568                         free(cp);
569                 }
570         }
571         i = format_len + char_read + 256;
572         scanl = mh_xmalloc((size_t) i + 2);
573         dat[0] = 0;
574         dat[1] = 0;
575         dat[2] = 0;
576         dat[3] = OUTPUTLINELEN;
577         dat[4] = 0;
578         fmt_scan(fmt, scanl, i, dat);
579         fputs(scanl, out);
580         if (badaddrs) {
581                 fputs("\nrepl: bad addresses:\n", out);
582                 fputs( badaddrs, out);
583         }
584
585         /* Check if we should filter the message */
586         if (filter) {
587                 fflush(out);
588                 if (ferror(out))
589                         adios(drft, "error writing");
590
591                 replfilter(inb, out, filter);
592         }
593
594         fflush(out);
595         if (ferror(out))
596                 adios(drft, "error writing");
597         fclose(out);
598
599         /* if we want mime, then add an attachment header */
600         if (!filter && mime && mp) {
601                 char buffer[BUFSIZ];
602
603                 snprintf(buffer, sizeof buffer, "+%s %s",
604                                 mp->foldpath, m_name(mp->lowsel));
605                 annotate(drft, attach_hdr, buffer, 0, -2, 1);
606         }
607
608         /* return dynamically allocated buffers */
609         free(scanl);
610         for (nxtbuf = compbuffers, i = ncomps; (cptr = *savecomp++);
611                         nxtbuf++, i--)
612                 free(cptr->c_text);  /* if not nxtbuf, nxtbuf already freed */
613         while ( i-- > 0)
614                 free(*nxtbuf++);  /* free unused nxtbufs */
615         free((char *) compbuffers);
616         free((char *) used_buf);
617 }
618
619 static char *buf;  /* our current working buffer */
620 static char *bufend;  /* end of working buffer */
621 static char *last_dst;  /* buf ptr at end of last call */
622 static unsigned int bufsiz=0;  /* current size of buf */
623
624 #define BUFINCR 512  /* how much to expand buf when if fills */
625
626 #define CPY(s) { cp = (s); while ((*dst++ = *cp++)) ; --dst; }
627
628 /*
629 ** check if there's enough room in buf for str.
630 ** add more mem if needed
631 */
632 #define CHECKMEM(str) \
633         if ((len = strlen(str)) >= bufend - dst) {\
634                 int i = dst - buf;\
635                 int n = last_dst - buf;\
636                 bufsiz += ((dst + len - bufend) / BUFINCR + 1) * BUFINCR;\
637                 buf = mh_xrealloc(buf, bufsiz);\
638                 dst = buf + i;\
639                 last_dst = buf + n;\
640                 bufend = buf + bufsiz;\
641         }
642
643
644 /*
645 ** fmt_scan will call this routine if the user includes the function
646 ** "(formataddr {component})" in a format string.  "orig" is the
647 ** original contents of the string register.  "str" is the address
648 ** string to be formatted and concatenated onto orig.  This routine
649 ** returns a pointer to the concatenated address string.
650 **
651 ** We try to not do a lot of malloc/copy/free's (which is why we
652 ** don't call "getcpy") but still place no upper limit on the
653 ** length of the result string.
654 **
655 ** This routine is an override for the equally named one in sbr/fmt_addr.c.
656 ** Don't delete it!
657 */
658 char *
659 formataddr(char *orig, char *str)
660 {
661         register int len;
662         char baddr[BUFSIZ], error[BUFSIZ];
663         register int isgroup;
664         register char *dst;
665         register char *cp;
666         register char *sp;
667         register struct mailname *mp = NULL;
668
669         /* if we don't have a buffer yet, get one */
670         if (bufsiz == 0) {
671                 buf = mh_xmalloc(BUFINCR);
672                 last_dst = buf;  /* XXX */
673                 bufsiz = BUFINCR - 6;  /* leave some slop */
674                 bufend = buf + bufsiz;
675         }
676         /*
677         ** If "orig" points to our buffer we can just pick up where we
678         ** left off.  Otherwise we have to copy orig into our buffer.
679         */
680         if (orig == buf)
681                 dst = last_dst;
682         else if (!orig || !*orig) {
683                 dst = buf;
684                 *dst = '\0';
685         } else {
686                 dst = last_dst;  /* XXX */
687                 CHECKMEM(orig);
688                 CPY(orig);
689         }
690
691         /* concatenate all the new addresses onto 'buf' */
692         for (isgroup = 0; (cp = getname(str)); ) {
693                 if ((mp = getm(cp, dfhost, dftype, AD_NAME, error)) == NULL) {
694                         snprintf(baddr, sizeof(baddr), "\t%s -- %s\n",
695                                         cp, error);
696                         badaddrs = add(baddr, badaddrs);
697                         continue;
698                 }
699                 if (isgroup && (mp->m_gname || !mp->m_ingrp)) {
700                         *dst++ = ';';
701                         isgroup = 0;
702                 }
703                 if (insert(mp)) {
704                         /* if we get here we're going to add an address */
705                         if (dst != buf) {
706                                 *dst++ = ',';
707                                 *dst++ = ' ';
708                         }
709                         if (mp->m_gname) {
710                                 CHECKMEM(mp->m_gname);
711                                 CPY(mp->m_gname);
712                                 isgroup++;
713                         }
714                         sp = adrformat(mp);
715                         CHECKMEM(sp);
716                         CPY(sp);
717                 }
718         }
719
720         if (isgroup)
721                 *dst++ = ';';
722
723         *dst = '\0';
724         last_dst = dst;
725         return (buf);
726 }
727
728
729 static int
730 insert(struct mailname *np)
731 {
732         char buffer[BUFSIZ];
733         register struct mailname *mp;
734
735         if (np->m_mbox == NULL)
736                 return 0;
737
738         for (mp = &mq; mp->m_next; mp = mp->m_next) {
739                 if (!mh_strcasecmp(np->m_host, mp->m_next->m_host) &&
740                                 !mh_strcasecmp(np->m_mbox, mp->m_next->m_mbox))
741                         return 0;
742         }
743         if (!ccme && ismymbox(np))
744                 return 0;
745
746         if (querysw) {
747                 snprintf(buffer, sizeof(buffer), "Reply to %s? ",
748                                 adrformat(np));
749                 if (!gans(buffer, anoyes))
750                 return 0;
751         }
752         mp->m_next = np;
753
754 #ifdef ISI
755         if (ismymbox(np))
756                 ccme = 0;
757 #endif
758
759         return 1;
760 }
761
762
763 /*
764 ** Call the mhlproc
765 **
766 ** This function expects that argument out has been fflushed by the caller.
767 */
768
769 static void
770 replfilter(FILE *in, FILE *out, char *filter)
771 {
772         int pid;
773         char *mhl;
774         char *errstr;
775
776         if (filter == NULL)
777                 return;
778
779         if (access(filter, R_OK) == NOTOK)
780                 adios(filter, "unable to read");
781
782         mhl = mhbasename(mhlproc);
783
784         rewind(in);
785         lseek(fileno(in), (off_t) 0, SEEK_SET);
786
787         switch (pid = fork()) {
788         case NOTOK:
789                 adios("fork", "unable to");
790
791         case OK:
792                 dup2(fileno(in), fileno(stdin));
793                 dup2(fileno(out), fileno(stdout));
794                 closefds(3);
795
796                 execlp(mhlproc, mhl, "-form", filter, "-noclear", NULL);
797                 errstr = strerror(errno);
798                 write(2, "unable to exec ", 15);
799                 write(2, mhlproc, strlen(mhlproc));
800                 write(2, ": ", 2);
801                 write(2, errstr, strlen(errstr));
802                 write(2, "\n", 1);
803                 _exit(-1);
804
805         default:
806                 if (pidXwait(pid, mhl))
807                         done(1);
808                 fseek(out, 0L, SEEK_END);
809                 break;
810         }
811 }