2 * This is just a little hack to copy standard input to a message in Aide>
4 * Copyright (c) 1987-2012 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
23 #include "citadel_dirs.h"
26 * Simplified function to generate a message in our format
28 static void ap_make_message(FILE *fp, char *target_room, char *author, char *subject)
37 fprintf(fp, "Proom_aide");
39 fprintf(fp, "T%ld", (long)now);
41 fprintf(fp, "A%s", author);
43 fprintf(fp, "O%s", target_room);
45 if (strlen(subject) > 0) {
46 fprintf(fp, "U%s%c", subject, 0);
50 while (a = getc(stdin), a > 0) {
65 int main(int argc, char **argv)
68 char target_room[ROOMNAMELEN];
71 FILE *tempfp, *spoolfp;
76 char relhome[PATH_MAX]="";
77 char ctdldir[PATH_MAX]=CTDLDIR;
79 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
81 strcpy(target_room, "Aide");
82 strcpy(author, "Citadel");
84 for (i=1; i<argc; ++i) {
85 if (!strncasecmp(argv[i], "-r", 2)) {
86 strncpy(target_room, &argv[i][2], sizeof(target_room));
87 target_room[sizeof(target_room)-1] = 0;
89 else if (!strncasecmp(argv[i], "-a", 2)) {
90 strncpy(author, &argv[i][2], sizeof(author));
91 author[sizeof(author)-1] = 0;
93 else if (!strncasecmp(argv[i], "-s", 2)) {
94 strncpy(subject, &argv[i][2], sizeof(subject));
95 subject[sizeof(subject)-1] = 0;
97 fprintf(stderr, "%s: usage: %s "
98 "[-rTargetRoom] [-aAuthor] [-sSubject]\n",
104 snprintf(tempspool, sizeof tempspool, "%s/ap.%04x.%08lx", ctdl_netin_dir, getpid(), time(NULL));
105 unlink(tempspool); /* unlinking it for now, keeps it from being posted prematurely */
107 tempfp = fopen(tempspool, "w+b");
109 if (tempfp == NULL) {
110 perror("cannot open temp file");
114 /* Generate a message from stdin */
115 ap_make_message(tempfp, target_room, author, subject);
117 /* Copy it to a new temp file in the spool directory */
120 spoolfp = fopen(tempspool, "wb");
121 if (spoolfp == NULL) {
122 perror("cannot open spool file");
125 while (ch = getc(tempfp), (ch >= 0)) {
130 return(fclose(spoolfp));