/[anubis]/anubis/src/files.c
ViewVC logotype

Diff of /anubis/src/files.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by gray, Thu Feb 6 15:47:36 2003 UTC revision 1.3 by gray, Wed Feb 26 16:52:23 2003 UTC
# Line 25  Line 25 
25  #include "headers.h"  #include "headers.h"
26  #include "extern.h"  #include "extern.h"
27    
 static void append_text_file(void);  
 static void append_signature_file(char *);  
   
 void  
 check_all_files(char *user)  
 {  
         if (mopt & M_BODYAPPEND)  
                 append_text_file();  
         if (mopt & M_SIGNATURE)  
                 append_signature_file(user);  
         return;  
 }  
   
28  static void  static void
29  append_text_file(void)  _append_text_file(MESSAGE *msg, char *filename, char *prefix)
30  {  {
31          FILE *fptxt;          FILE *fptxt;
32          char buf[LINEBUFFER+1];          char buf[LINEBUFFER+1];
33          unsigned long nbytes;          unsigned long nbytes;
34          unsigned long nlines = 0;          unsigned long nlines = 0;
35            char *p;
36          fptxt = fopen(message.body_append, "r");          
37            fptxt = fopen(filename, "r");
38          if (fptxt == 0) {          if (fptxt == 0) {
39                  anubis_error(HARD, "%s: %s.", message.body_append, strerror(errno));                  anubis_error(HARD,
40                                 "%s: %s.", filename, strerror(errno));
41                  return;                  return;
42          }          }
43          while (fgets(buf, LINEBUFFER, fptxt) != 0)          while (fgets(buf, LINEBUFFER, fptxt) != 0)
# Line 58  append_text_file(void) Line 47  append_text_file(void)
47          clearerr(fptxt);          clearerr(fptxt);
48          nbytes = ftell(fptxt);          nbytes = ftell(fptxt);
49          rewind(fptxt);          rewind(fptxt);
50          nbytes = strlen(message.body) + nbytes + nlines + 3;          nbytes = strlen(msg->body)
51                    + (prefix ? strlen(prefix) : 0)
52          message.body = (char *)xrealloc((char *)message.body, nbytes);                  + nbytes + nlines + 1;
53          strcat(message.body, CRLF);          
54          nbytes -= (strlen(message.body) + 1);          msg->body = (char *)xrealloc((char *)msg->body, nbytes);
55          while (fgets(buf, LINEBUFFER - 2, fptxt) != 0)          p = msg->body + strlen(msg->body);
56          {          if (prefix) {
57                  remcrlf(buf);                  strcpy(p, prefix);
58                  strcat(buf, CRLF);                  p += strlen(prefix);
59                  strncat(message.body, buf, nbytes);          }
60                  nbytes -= strlen(buf);          while (fgets(buf, LINEBUFFER - 1, fptxt) != 0) {
61                    strcpy(p, buf);
62                    p += strlen(buf);
63          }          }
64            *p = 0;
65          fclose(fptxt);          fclose(fptxt);
66          return;          return;
67  }  }
68    
69  static void  void
70  append_signature_file(char *user)  message_append_text_file(MESSAGE *msg, char *filename)
71    {
72            _append_text_file(msg, filename, NULL);
73    }
74    
75    
76    void
77    message_append_signature_file(MESSAGE *msg, char *user)
78  {  {
         int n;  
         FILE *fpsig;  
         unsigned long nbytes;  
         unsigned long nlines = 0;  
79          char homedir[MAXPATHLEN+1];          char homedir[MAXPATHLEN+1];
         char buf[LINEBUFFER+1];  
80          char signature_file[] = DEFAULT_SIGFILE;          char signature_file[] = DEFAULT_SIGFILE;
81          char *signature_path = 0;          char *signature_path = 0;
82            size_t n;
83            
84          get_homedir(user, homedir, sizeof(homedir));          get_homedir(user, homedir, sizeof(homedir));
85    
86          n = strlen(homedir) + strlen(signature_file) + 2;          n = strlen(homedir) + strlen(signature_file) + 2;
         n = n > MAXPATHLEN ? MAXPATHLEN + 1 : n + 1;  
87          signature_path = (char *)xmalloc(n);          signature_path = (char *)xmalloc(n);
88          snprintf(signature_path, n - 1, "%s/%s", homedir, signature_file);          snprintf(signature_path, n - 1, "%s/%s", homedir, signature_file);
89    
90          fpsig = fopen(signature_path, "r");          _append_text_file(msg, signature_path, "\n--\n");
         if (fpsig == 0) {  
                 anubis_error(HARD, "%s: %s.", signature_path, strerror(errno));  
                 return;  
         }  
         while (fgets(buf, LINEBUFFER, fpsig) != 0)  
                 nlines++;  
   
         fseek(fpsig, 0L, SEEK_END);  
         clearerr(fpsig);  
         nbytes = ftell(fpsig);  
         rewind(fpsig);  
         nbytes = strlen(message.body) + nbytes + nlines + 10;  
   
         message.body = (char *)xrealloc((char *)message.body, nbytes);  
         strcat(message.body, CRLF"-- "CRLF);  
         nbytes -= (strlen(message.body) + 1);  
         while (fgets(buf, LINEBUFFER - 2, fpsig) != 0)  
         {  
                 remcrlf(buf);  
                 strcat(buf, CRLF);  
                 strncat(message.body, buf, nbytes);  
                 nbytes -= strlen(buf);  
         }  
         strncat(message.body, CRLF, nbytes);  
91          free(signature_path);          free(signature_path);
         fclose(fpsig);  
92          return;          return;
93  }  }
94    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26