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"
31 * Simplified function to generate a message in our format
33 static void ap_make_message(FILE *fp, char *target_room, char *author, char *subject)
42 fprintf(fp, "Proom_aide");
44 fprintf(fp, "T%ld", (long)now);
46 fprintf(fp, "A%s", author);
48 fprintf(fp, "O%s", target_room);
50 if (strlen(subject) > 0) {
51 fprintf(fp, "U%s%c", subject, 0);
55 while (a = getc(stdin), a > 0) {
70 int main(int argc, char **argv)
73 char target_room[ROOMNAMELEN];
76 FILE *tempfp, *spoolfp;
81 char relhome[PATH_MAX]="";
82 char ctdldir[PATH_MAX]=CTDLDIR;
84 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
86 strcpy(target_room, "Aide");
87 strcpy(author, "Citadel");
89 for (i=1; i<argc; ++i) {
90 if (!strncasecmp(argv[i], "-r", 2)) {
91 strncpy(target_room, &argv[i][2], sizeof(target_room));
92 target_room[sizeof(target_room)-1] = 0;
94 else if (!strncasecmp(argv[i], "-a", 2)) {
95 strncpy(author, &argv[i][2], sizeof(author));
96 author[sizeof(author)-1] = 0;
98 else if (!strncasecmp(argv[i], "-s", 2)) {
99 strncpy(subject, &argv[i][2], sizeof(subject));
100 subject[sizeof(subject)-1] = 0;
102 fprintf(stderr, "%s: usage: %s "
103 "[-rTargetRoom] [-aAuthor] [-sSubject]\n",
109 snprintf(tempspool, sizeof tempspool, "%s/ap.%04x.%08lx", ctdl_netin_dir, getpid(), time(NULL));
110 unlink(tempspool); /* unlinking it for now, keeps it from being posted prematurely */
112 tempfp = fopen(tempspool, "w+b");
114 if (tempfp == NULL) {
115 perror("cannot open temp file");
119 /* Generate a message from stdin */
120 ap_make_message(tempfp, target_room, author, subject);
122 /* Copy it to a new temp file in the spool directory */
125 spoolfp = fopen(tempspool, "wb");
126 if (spoolfp == NULL) {
127 perror("cannot open spool file");
130 while (ch = getc(tempfp), (ch >= 0)) {
135 return(fclose(spoolfp));