to enable debugging to stderr. Fixed an error message or two. Also
saved the hostname extracted from the LMTP greeting so we can pass it
right back to the LMTP server as part of the LHLO command.
#endif
#include "citadel_dirs.h"
#endif
#include "citadel_dirs.h"
-/* #define DEBUG */ /* uncomment to get protocol traces */
-
void strip_trailing_nonprint(char *buf)
{
void strip_trailing_nonprint(char *buf)
{
*/
buf[i] = 0;
strip_trailing_nonprint(buf);
*/
buf[i] = 0;
strip_trailing_nonprint(buf);
-#ifdef DEBUG
- printf("> %s\n", buf);
-#endif
+ if (debug) fprintf(stderr, "> %s\n", buf);
*/
void serv_puts(char *buf)
{
*/
void serv_puts(char *buf)
{
-#ifdef DEBUG
- printf("< %s\n", buf);
-#endif
+ if (debug) fprintf(stderr, "< %s\n", buf);
serv_write(buf, strlen(buf));
serv_write("\n", 1);
}
serv_write(buf, strlen(buf));
serv_write("\n", 1);
}
void cleanup(int exitcode) {
char buf[1024];
void cleanup(int exitcode) {
char buf[1024];
- if (exitcode == 1)
- printf ("Error while sending mail."
- "Check your maildata and make shure "
- "citadel is configured properly!");
+ if (exitcode != 0) {
+ fprintf(stderr, "Error while sending mail. Please check your Citadel configuration.\n");
+ }
serv_puts("QUIT");
serv_gets(buf);
exit(exitcode);
serv_puts("QUIT");
serv_gets(buf);
exit(exitcode);
char relhome[PATH_MAX]="";
char ctdldir[PATH_MAX]=CTDLDIR;
char *sp, *ep;
char relhome[PATH_MAX]="";
char ctdldir[PATH_MAX]=CTDLDIR;
char *sp, *ep;
+ for (i=1; i<argc; ++i) {
+ if (!strcmp(argv[i], "-d")) {
+ debug = 1;
+ }
+ }
+
/* TODO: should we be able to calculate relative dirs? */
calc_dirs_n_files(relh, home, relhome, ctdldir);
/* TODO: should we be able to calculate relative dirs? */
calc_dirs_n_files(relh, home, relhome, ctdldir);
ep = strchr (sp, ' ');
if (ep == NULL) cleanup(1);
*ep = '\0';
ep = strchr (sp, ' ');
if (ep == NULL) cleanup(1);
*ep = '\0';
+ strncpy(hostname, sp, sizeof hostname);
snprintf(fromline, sizeof fromline, "From: %s@%s",
pw->pw_name,
snprintf(fromline, sizeof fromline, "From: %s@%s",
pw->pw_name,
);
while (fgets(buf, 1024, stdin) != NULL) {
if ( ( (buf[0] == 13) || (buf[0] == 10)) && (in_body == 0) ) {
);
while (fgets(buf, 1024, stdin) != NULL) {
if ( ( (buf[0] == 13) || (buf[0] == 10)) && (in_body == 0) ) {
}
strip_trailing_nonprint(fromline);
}
strip_trailing_nonprint(fromline);
+ sprintf(buf, "LHLO %s", hostname);
+ serv_puts(buf);
do {
serv_gets(buf);
strcat(buf, " ");
do {
serv_gets(buf);
strcat(buf, " ");
snprintf(buf, sizeof buf, "MAIL %s", fromline);
serv_puts(buf);
serv_gets(buf);
snprintf(buf, sizeof buf, "MAIL %s", fromline);
serv_puts(buf);
serv_gets(buf);
- if (buf[0]!='2') cleanup(1);
+ if (buf[0] != '2') cleanup(1);
for (i=1; i<argc; ++i) {
if (argv[i][0] != '-') {
snprintf(buf, sizeof buf, "RCPT To: %s", argv[i]);
serv_puts(buf);
serv_gets(buf);
for (i=1; i<argc; ++i) {
if (argv[i][0] != '-') {
snprintf(buf, sizeof buf, "RCPT To: %s", argv[i]);
serv_puts(buf);
serv_gets(buf);
- /* if (buf[0]!='2') cleanup(1); */
+ /* if (buf[0] != '2') cleanup(1); */
}
serv_puts(".");
serv_gets(buf);
}
serv_puts(".");
serv_gets(buf);
- if (buf[0]!='2') cleanup(1);
- else cleanup(0);
+ if (buf[0] != '2') {
+ cleanup(1);
+ }
+ else {
+ cleanup(0);
+ }
+
+ /* We won't actually reach this statement but the compiler will
+ * display a spurious warning about an invalid return type if
+ * we don't return an int.
+ */