/[monit]/monit/sendmail.c
ViewVC logotype

Diff of /monit/sendmail.c

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

revision 1.20 by chopp, Wed Aug 13 22:18:43 2003 UTC revision 1.21 by hauk, Wed Sep 17 18:03:15 2003 UTC
# Line 75  Line 75 
75  /* ------------------------------------------------------- Private variables */  /* ------------------------------------------------------- Private variables */
76    
77    
 static Socket_T S;  
78  static char *server;  static char *server;
79  static sigjmp_buf error;  static sigjmp_buf error;
80    
# Line 83  static sigjmp_buf error; Line 82  static sigjmp_buf error;
82  /* -------------------------------------------------------------- Prototypes */  /* -------------------------------------------------------------- Prototypes */
83    
84    
85  static void do_status();  static void do_status(Socket_T S);
86  static void finalize_server();  static void do_send(Socket_T S, const char *, ...);
 static int  initialize_server();  
 static void do_send(const char *, ...);  
87    
88    
89  /* ------------------------------------------------------------------ Public */  /* ------------------------------------------------------------------ Public */
# Line 99  static void do_send(const char *, ...); Line 96  static void do_send(const char *, ...);
96  void sendmail(Mail_T mail) {  void sendmail(Mail_T mail) {
97    
98    Mail_T m;    Mail_T m;
99      Socket_T S;
100    char localhost[STRLEN];    char localhost[STRLEN];
101    char *now = get_RFC822date(NULL);    char *now = get_RFC822date(NULL);
102        
103    ASSERT(mail);    ASSERT(mail);
104      
105      server= Run.mailserver?Run.mailserver:LOCALHOST;
106    
107    if(gethostname(localhost, sizeof(localhost)) < 0) {    if(gethostname(localhost, sizeof(localhost)) < 0) {
108      snprintf(localhost, STRLEN, LOCALHOST);      snprintf(localhost, STRLEN, LOCALHOST);
109    }    }
110    
111        S= socket_new(server, SMTP_PORT, SOCKET_TCP, FALSE);
112    if(!initialize_server()) {    if(!S) {
113        log("Cannot open a connection to the mailserver '%s' -- %s\n",
114            server, STRERROR);
115      goto exit;      goto exit;
116    }    }
117        
# Line 117  void sendmail(Mail_T mail) { Line 119  void sendmail(Mail_T mail) {
119      goto exit;      goto exit;
120    }    }
121    
122    do_status();    do_status(S);
123    do_send("HELO %s\r\n", localhost);    do_send(S, "HELO %s\r\n", localhost);
124    do_status();    do_status(S);
125    
126    for(m= mail; m; m= m->next) {    for(m= mail; m; m= m->next) {
127            
128      do_send("MAIL FROM: <%s>\r\n", m->from);      do_send(S, "MAIL FROM: <%s>\r\n", m->from);
129      do_status();      do_status(S);
130      do_send("RCPT TO: <%s>\r\n", m->to);      do_send(S, "RCPT TO: <%s>\r\n", m->to);
131      do_status();      do_status(S);
132      do_send("DATA\r\n");      do_send(S, "DATA\r\n");
133      do_status();      do_status(S);
134      do_send("From: %s\r\n", m->from);      do_send(S, "From: %s\r\n", m->from);
135      do_send("To: %s\r\n", m->to);      do_send(S, "To: %s\r\n", m->to);
136      do_send("Subject: %s\r\n", m->subject);      do_send(S, "Subject: %s\r\n", m->subject);
137      do_send("Date: %s\r\n", now);      do_send(S, "Date: %s\r\n", now);
138      do_send("X-Mailer: %s %s\r\n", prog, VERSION);      do_send(S, "X-Mailer: %s %s\r\n", prog, VERSION);
139      do_send("Mime-Version: 1.0\r\n");      do_send(S, "Mime-Version: 1.0\r\n");
140      do_send("Content-Type: text/plain; charset=\"iso-8859-1\"\r\n");      do_send(S, "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n");
141      do_send("Content-Transfer-Encoding: quoted-printable\r\n");      do_send(S, "Content-Transfer-Encoding: quoted-printable\r\n");
142      do_send("\r\n");      do_send(S, "\r\n");
143      do_send("%s\r\n", m->message);      do_send(S, "%s\r\n", m->message);
144      if(m->opt_message) {      if(m->opt_message) {
145        do_send("%s\r\n", m->opt_message);        do_send(S, "%s\r\n", m->opt_message);
146      }      }
147      do_send(".\r\n");      do_send(S, ".\r\n");
148      do_status();      do_status(S);
149            
150    }    }
151    
152    do_send("QUIT\r\n");    do_send(S, "QUIT\r\n");
153        
154    exit:    exit:
155    free(now);    free(now);
   finalize_server();  
     
 }  
   
   
 /* ----------------------------------------------------------------- Private */  
   
   
 static int initialize_server() {  
     
   S= NULL;  
   server= Run.mailserver?Run.mailserver:LOCALHOST;  
     
   S= socket_new(server, SMTP_PORT, SOCKET_TCP, FALSE);  
   if(!S) {  
     log("Cannot open a connection to the mailserver '%s' -- %s\n",  
         server, STRERROR);  
     return FALSE;  
   }  
     
   return TRUE;  
     
 }  
   
   
 static void finalize_server() {  
     
156    if(S) {    if(S) {
157      socket_free(&S);      socket_free(&S);
158    }    }
# Line 185  static void finalize_server() { Line 160  static void finalize_server() {
160  }  }
161    
162    
163  void do_send(const char *format, ...) {  /* ----------------------------------------------------------------- Private */
164    
165    
166    void do_send(Socket_T S, const char *format, ...) {
167        
168    va_list ap;    va_list ap;
169    char msg[2048];    char msg[2048];
# Line 205  void do_send(const char *format, ...) { Line 183  void do_send(const char *format, ...) {
183  }  }
184    
185    
186  static void do_status() {  static void do_status(Socket_T S) {
187        
188    int  status;    int  status;
189    char buf[STRLEN];    char buf[STRLEN];

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21

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