/[mailutils]/mailutils/mail/send.c
ViewVC logotype

Diff of /mailutils/mail/send.c

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

revision 1.35 by gray, Mon Aug 18 14:00:28 2003 UTC revision 1.36 by gray, Tue Oct 28 15:40:25 2003 UTC
# Line 25  Line 25 
25  static int isfilename __P ((const char *));  static int isfilename __P ((const char *));
26  static void msg_to_pipe __P ((const char *cmd, message_t msg));  static void msg_to_pipe __P ((const char *cmd, message_t msg));
27    
28    
29    /* Additional message headers */
30    struct add_header
31    {
32      int mode;
33      char *name;
34      char *value;
35    };
36    
37    static list_t add_header_list;
38    
39    static int
40    seed_headers (void *item, void *data)
41    {
42      struct add_header *hp = item;
43      compose_env_t *env = data;
44    
45      compose_header_set (env, hp->name, hp->value, hp->mode);
46      return 0;
47    }
48    
49    static int
50    list_headers (void *item, void *data)
51    {
52      struct add_header *hp = item;
53      char *name = data;
54    
55      if (!name || strcmp (name, hp->name) == 0)
56        {
57          printf ("%s: %s\n", hp->name, hp->value);
58        }
59      return 0;
60    }
61        
62    static void
63    add_header (char *name, char *value, int mode)
64    {
65      struct add_header *hp;
66      
67      if (!add_header_list)
68        {
69          int rc = list_create (&add_header_list);
70          if (rc)
71            {
72              util_error (_("Cannot create header list: %s"), mu_strerror (rc));
73              exit (1);
74            }
75        }
76    
77      hp = xmalloc (sizeof (*hp));
78      hp->mode = mode;
79      hp->name = name;
80      hp->value = value;
81      list_append (add_header_list, hp);
82    }
83    
84    void
85    send_append_header (char *text)
86    {
87      char *p;
88      size_t len;
89      char *name;
90    
91      p = strchr (text, ':');
92      if (!p)
93        {
94          util_error (_("Invalid header: %s"), text);
95          return;
96        }
97      len = p - text;
98      name = xmalloc (len + 1);
99      memcpy (name, text, len);
100      name[len] = 0;
101      for (p++; *p && isspace (*p); p++)
102        ;
103    
104      add_header (name, strdup (p), COMPOSE_APPEND);
105    }
106    
107    void
108    send_append_header2 (char *name, char *value, int mode)
109    {
110      add_header (strdup (name), strdup (value), mode);
111    }
112    
113    int
114    mail_sendheader (int argc, char **argv)
115    {
116      if (argc == 1)
117        list_do (add_header_list, list_headers, NULL);
118      else if (argc == 2)
119        {
120          if (strchr (argv[1], ':'))
121            send_append_header (argv[1]);
122          else
123            list_do (add_header_list, list_headers, argv[1]);
124        }
125      else
126        {
127          size_t len = strlen (argv[1]);
128          if (len > 0 && argv[1][len - 1] == ':')
129            argv[1][len - 1] = 0;
130          add_header (strdup (argv[1]), strdup (argv[2]), COMPOSE_APPEND);
131        }
132      return 0;
133    }
134    
135    
136    /* Send-related commands */
137    
138  static void  static void
139  read_cc_bcc (compose_env_t *env)  read_cc_bcc (compose_env_t *env)
140  {  {
# Line 92  mail_send (int argc, char **argv) Line 202  mail_send (int argc, char **argv)
202    if (util_getenv (NULL, "asksub", Mail_env_boolean, 0) == 0)    if (util_getenv (NULL, "asksub", Mail_env_boolean, 0) == 0)
203      compose_header_set (&env, MU_HEADER_SUBJECT,      compose_header_set (&env, MU_HEADER_SUBJECT,
204                          ml_readline_with_intr ("Subject: "), COMPOSE_REPLACE);                          ml_readline_with_intr ("Subject: "), COMPOSE_REPLACE);
   else  
     {  
       char *p;  
       if (util_getenv (&p, "subject", Mail_env_string, 0) == 0)  
         compose_header_set (&env, MU_HEADER_SUBJECT, p, COMPOSE_REPLACE);  
     }  
205    
206    status = mail_send0 (&env, save_to);    status = mail_send0 (&env, save_to);
207    compose_destroy (&env);    compose_destroy (&env);
# Line 108  void Line 212  void
212  compose_init (compose_env_t * env)  compose_init (compose_env_t * env)
213  {  {
214    memset (env, 0, sizeof (*env));    memset (env, 0, sizeof (*env));
215      list_do (add_header_list, seed_headers, env);
216  }  }
217    
218  int  int

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.36

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