- time_t now;
- FILE *temp;
- int a;
- int format_type = 0;
- char buf[128];
- char from[512];
- char userbuf[256];
- char frombuf[256];
- char nodebuf[256];
- char destsys[256];
- char subject[256];
- char targetroom[256];
- char content_type[256];
- char *extra_headers = NULL;
-
-
- if (dtype == REMOTE) {
-
- /* get the Citadel node name out of the path */
- strncpy(destsys, recp, sizeof(destsys));
- for (a = 0; a < strlen(destsys); ++a) {
- if ((destsys[a] == '!') || (destsys[a] == '.')) {
- destsys[a] = 0;
- }
- }
-
- /* chop the system name out, so we're left with a user */
- while (haschar(recp, '!'))
- strcpy(recp, &recp[1]);
- }
- /* Convert underscores to spaces */
- for (a = 0; a < strlen(recp); ++a)
- if (recp[a] == '_')
- recp[a] = ' ';
-
- /* Are we delivering to a room instead of a user? */
- if (!strncasecmp(recp, "room ", 5)) {
- strcpy(targetroom, &recp[5]);
- strcpy(recp, "");
- } else {
- strcpy(targetroom, MAILROOM);
- }
-
- time(&now);
- snprintf(from, sizeof from, "postmaster@%s", config.c_nodename);
-
- snprintf(buf, sizeof buf, "./network/spoolin/citmail.%d", getpid());
- temp = fopen(buf, "w");
-
- strcpy(subject, "");
- strcpy(nodebuf, config.c_nodename);
- strcpy(content_type, "text/plain");
-
- do {
- if (fgets(buf, 128, stdin) == NULL)
- strcpy(buf, ".");
- strip_trailing_whitespace(buf);
-
- if (!strncasecmp(buf, "Subject: ", 9))
- strcpy(subject, &buf[9]);
- else if (!strncasecmp(buf, "Date: ", 6))
- now = conv_date(&buf[6]);
- else if (!strncasecmp(buf, "From: ", 6))
- strcpy(from, &buf[6]);
- else if (!strncasecmp(buf, "Content-type: ", 14))
- strcpy(content_type, &buf[14]);
- else if (!strncasecmp(buf, "From ", 5)) { /* ignore */
- } else {
- if (extra_headers == NULL) {
- extra_headers = malloc(strlen(buf) + 2);
- strcpy(extra_headers, "");
- } else {
- extra_headers = realloc(extra_headers,
- (strlen(extra_headers) + strlen(buf) + 2));
- }
- strcat(extra_headers, buf);
- strcat(extra_headers, "\n");
- }
- } while ((strcmp(buf, ".")) && (strcmp(buf, "")));
-
- process_rfc822_addr(from, userbuf, nodebuf, frombuf);
-
- if (!strncasecmp(content_type, "text/plain", 10))
- format_type = 1; /* plain ASCII message */
- else
- format_type = 4; /* MIME message */
-
- /* now convert it to Citadel format */
-
- /* Header bytes */
- putc(255, temp); /* 0xFF = start-of-message byte */
- putc(MES_NORMAL, temp); /* Non-anonymous message */
- putc(format_type, temp); /* Format type */