citadel
About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).
  Fossies Dox: citadel.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

serv_messages.c
Go to the documentation of this file.
1// Message-related protocol commands for Citadel clients
2//
3// Copyright (c) 1987-2021 by the citadel.org team
4//
5// This program is open source software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License version 3.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12
13#include <stdio.h>
14#include <libcitadel.h>
15#include "citserver.h"
16#include "ctdl_module.h"
17#include "internet_addressing.h"
18#include "user_ops.h"
19#include "room_ops.h"
20#include "config.h"
21
22extern char *msgkeys[];
23
24
25// Back end for the MSGS command: output message number only.
26void simple_listing(long msgnum, void *userdata) {
27 cprintf("%ld\n", msgnum);
28}
29
30
31// Back end for the MSGS command: output header summary.
32void headers_listing(long msgnum, void *userdata) {
33 struct CtdlMessage *msg;
34 int output_mode = *(int *)userdata;
35
36 msg = CtdlFetchMessage(msgnum, 0);
37 if (msg == NULL) {
38 cprintf("%ld|0|||||||\n", msgnum);
39 return;
40 }
41
42 // change all vertical bars in the subject to hyphens so it doesn't screw up the protocol
43 if (!CM_IsEmpty(msg, eMsgSubject)) {
44 char *p;
45 for (p=msg->cm_fields[eMsgSubject]; *p; p++) {
46 if (*p == '|') {
47 *p = '-';
48 }
49 }
50 }
51
52 // output all fields except the references hash
53 cprintf("%ld|%s|%s|%s|%s|%s",
54 msgnum,
55 (!CM_IsEmpty(msg, eTimestamp) ? msg->cm_fields[eTimestamp] : "0"),
56 (!CM_IsEmpty(msg, eAuthor) ? msg->cm_fields[eAuthor] : ""),
57 CtdlGetConfigStr("c_nodename"), // no more nodenames anymore
58 (!CM_IsEmpty(msg, erFc822Addr) ? msg->cm_fields[erFc822Addr] : ""),
59 (!CM_IsEmpty(msg, eMsgSubject) ? msg->cm_fields[eMsgSubject] : "")
60 );
61
62 if (output_mode == MSG_HDRS_THREADS) { // field view with thread hashes
63
64 // output the references hash
65 cprintf ("|%d|",
66 (!CM_IsEmpty(msg, emessageId) ? HashLittle(msg->cm_fields[emessageId],strlen(msg->cm_fields[emessageId])) : 0)
67 );
68
69 // output the references hash (yes it's ok that we're trashing the source buffer by doing this)
70 if (!CM_IsEmpty(msg, eWeferences)) {
71 char *token;
72 char *rest = msg->cm_fields[eWeferences];
73 char *prev = rest;
74 while((token = strtok_r(rest, "|", &rest))) {
75 cprintf("%d%s", HashLittle(token,rest-prev-(*rest==0?0:1)), (*rest==0?"":","));
76 prev = rest;
77 }
78 }
79
80 cprintf("|\n");
81 }
82
83 else { // field view with no threads, subject extends out forever
84 cprintf("\n");
85 }
86
87 CM_Free(msg);
88}
89
90typedef struct _msg_filter {
91 HashList *Filter;
92 HashPos *p;
93 StrBuf *buffer;
95
96
97void headers_brief_filter(long msgnum, void *userdata) {
98 long i, l;
99 struct CtdlMessage *msg;
100 msg_filter *flt = (msg_filter*) userdata;
101
102 l = GetCount(flt->Filter);
103 msg = CtdlFetchMessage(msgnum, 0);
104 StrBufPrintf(flt->buffer, "%ld", msgnum);
105 if (msg == NULL) {
106 for (i = 0; i < l; i++) {
107 StrBufAppendBufPlain(flt->buffer, HKEY("|"), 0);
108 }
109 }
110 else {
111 const char *k;
112 long len;
113 void *v;
114 RewindHashPos(flt->Filter, flt->p, 0);
115 while (GetNextHashPos(flt->Filter, flt->p, &len, &k, &v)) {
116 eMsgField f = (eMsgField) v;
117
118 StrBufAppendBufPlain(flt->buffer, HKEY("|"), 0);
119 if (!CM_IsEmpty(msg, f)) {
120 StrBufAppendBufPlain(flt->buffer, CM_KEY(msg, f), 0);
121 }
122 }
123 }
124 StrBufAppendBufPlain(flt->buffer, HKEY("\n"), 0);
125 cputbuf(flt->buffer);
126}
127
128// Back end for the MSGS command: output EUID header.
129void headers_euid(long msgnum, void *userdata) {
130 struct CtdlMessage *msg;
131
132 msg = CtdlFetchMessage(msgnum, 0);
133 if (msg == NULL) {
134 cprintf("%ld||\n", msgnum);
135 return;
136 }
137
138 cprintf("%ld|%s|%s\n",
139 msgnum,
140 (!CM_IsEmpty(msg, eExclusiveID) ? msg->cm_fields[eExclusiveID] : ""),
141 (!CM_IsEmpty(msg, eTimestamp) ? msg->cm_fields[eTimestamp] : "0"));
142 CM_Free(msg);
143}
144
145
146// cmd_msgs() - get list of message #'s in this room
147// implements the MSGS server command using CtdlForEachMessage()
148void cmd_msgs(char *cmdbuf) {
149 int mode = 0;
150 char which[16];
151 char buf[256];
152 char tfield[256];
153 char tvalue[256];
154 int cm_ref = 0;
155 int with_template = 0;
156 struct CtdlMessage *template = NULL;
157 msg_filter filt;
158 char search_string[1024];
159 ForEachMsgCallback CallBack;
160
162
163 extract_token(which, cmdbuf, 0, '|', sizeof which);
164 cm_ref = extract_int(cmdbuf, 1);
165 extract_token(search_string, cmdbuf, 1, '|', sizeof search_string);
166 with_template = extract_int(cmdbuf, 2);
167 int output_mode = extract_int(cmdbuf, 3);
168 switch (output_mode) {
169 default:
170 case MSG_HDRS_BRIEF:
171 CallBack = simple_listing;
172 break;
173 case MSG_HDRS_ALL:
174 case MSG_HDRS_THREADS:
175 CallBack = headers_listing;
176 break;
177 case MSG_HDRS_EUID:
178 CallBack = headers_euid;
179 break;
181 with_template = 2;
182 CallBack = headers_brief_filter;
183 break;
184 }
185
186 strcat(which, " ");
187 if (!strncasecmp(which, "OLD", 3))
188 mode = MSGS_OLD;
189 else if (!strncasecmp(which, "NEW", 3))
190 mode = MSGS_NEW;
191 else if (!strncasecmp(which, "FIRST", 5))
192 mode = MSGS_FIRST;
193 else if (!strncasecmp(which, "LAST", 4))
194 mode = MSGS_LAST;
195 else if (!strncasecmp(which, "GT", 2))
196 mode = MSGS_GT;
197 else if (!strncasecmp(which, "LT", 2))
198 mode = MSGS_LT;
199 else if (!strncasecmp(which, "SEARCH", 6))
200 mode = MSGS_SEARCH;
201 else
202 mode = MSGS_ALL;
203
204 if ( (mode == MSGS_SEARCH) && (!CtdlGetConfigInt("c_enable_fulltext")) ) {
205 cprintf("%d Full text index is not enabled on this server.\n",
207 return;
208 }
209
210 if (with_template == 1) {
211 memset(buf, 0, 5);
213 cprintf("%d Send template then receive message list\n",
215 template = (struct CtdlMessage *)
216 malloc(sizeof(struct CtdlMessage));
217 memset(template, 0, sizeof(struct CtdlMessage));
218 template->cm_magic = CTDLMESSAGE_MAGIC;
219 template->cm_anon_type = MES_NORMAL;
220
221 while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
222 eMsgField f;
223 long tValueLen;
224
225 tValueLen = extract_token(tfield, buf, 0, '|', sizeof tfield);
226 if ((tValueLen == 4) && GetFieldFromMnemonic(&f, tfield))
227 {
228 tValueLen = extract_token(tvalue, buf, 1, '|', sizeof tvalue);
229 if (tValueLen >= 0) {
230 CM_SetField(template, f, tvalue, tValueLen);
231 }
232 }
233 }
235 }
236 else if (with_template == 2) {
237 long i = 0;
238 memset(buf, 0, 5);
239 cprintf("%d Send list of headers\n",
241 filt.Filter = NewHash(1, lFlathash);
242 filt.buffer = NewStrBufPlain(NULL, 1024);
243 while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
244 eMsgField f;
245
246 if (GetFieldFromMnemonic(&f, buf))
247 {
248 Put(filt.Filter, LKEY(i), (void*)f, reference_free_handler);
249 i++;
250 }
251 }
252 filt.p = GetNewHashPos(filt.Filter, 0);
254 }
255 else {
256 cprintf("%d \n", LISTING_FOLLOWS);
257 }
258
259 if (with_template < 2) {
261 ( (mode == MSGS_SEARCH) ? 0 : cm_ref ),
262 ( (mode == MSGS_SEARCH) ? search_string : NULL ),
263 NULL,
264 template,
265 CallBack,
266 &output_mode);
267 if (template != NULL) CM_Free(template);
268 }
269 else {
271 ( (mode == MSGS_SEARCH) ? 0 : cm_ref ),
272 ( (mode == MSGS_SEARCH) ? search_string : NULL ),
273 NULL,
274 NULL,
275 CallBack,
276 &filt);
277 DeleteHashPos(&filt.p);
278 DeleteHash(&filt.Filter);
279 FreeStrBuf(&filt.buffer);
280
281 }
282 cprintf("000\n");
283}
284
285
286/*
287 * display a message (mode 0 - Citadel proprietary)
288 */
289void cmd_msg0(char *cmdbuf)
290{
291 long msgid;
292 int headers_only = HEADERS_ALL;
293
294 msgid = extract_long(cmdbuf, 0);
295 headers_only = extract_int(cmdbuf, 1);
296
297 CtdlOutputMsg(msgid, MT_CITADEL, headers_only, 1, 0, NULL, 0, NULL, NULL, NULL);
298 return;
299}
300
301
302// display a message (mode 2 - RFC822)
303void cmd_msg2(char *cmdbuf) {
304 long msgid;
305 int headers_only = HEADERS_ALL;
306
307 msgid = extract_long(cmdbuf, 0);
308 headers_only = extract_int(cmdbuf, 1);
309
310 CtdlOutputMsg(msgid, MT_RFC822, headers_only, 1, 1, NULL, 0, NULL, NULL, NULL);
311}
312
313
314// Display a message using MIME content types
315void cmd_msg4(char *cmdbuf) {
316 long msgid;
317 char section[64];
318
319 msgid = extract_long(cmdbuf, 0);
320 extract_token(section, cmdbuf, 1, '|', sizeof section);
321 CtdlOutputMsg(msgid, MT_MIME, 0, 1, 0, (section[0] ? section : NULL) , 0, NULL, NULL, NULL);
322}
323
324
325// Client tells us its preferred message format(s)
326void cmd_msgp(char *cmdbuf) {
327 if (!strcasecmp(cmdbuf, "dont_decode")) {
328 CC->msg4_dont_decode = 1;
329 cprintf("%d MSG4 will not pre-decode messages.\n", CIT_OK);
330 }
331 else {
332 safestrncpy(CC->preferred_formats, cmdbuf, sizeof(CC->preferred_formats));
333 cprintf("%d Preferred MIME formats have been set.\n", CIT_OK);
334 }
335}
336
337
338// Open a component of a MIME message as a download file
339void cmd_opna(char *cmdbuf) {
340 long msgid;
341 char desired_section[128];
342
343 msgid = extract_long(cmdbuf, 0);
344 extract_token(desired_section, cmdbuf, 1, '|', sizeof desired_section);
345 safestrncpy(CC->download_desired_section, desired_section,
346 sizeof CC->download_desired_section);
347 CtdlOutputMsg(msgid, MT_DOWNLOAD, 0, 1, 1, NULL, 0, NULL, NULL, NULL);
348}
349
350
351// Open a component of a MIME message and transmit it all at once
352void cmd_dlat(char *cmdbuf) {
353 long msgid;
354 char desired_section[128];
355
356 msgid = extract_long(cmdbuf, 0);
357 extract_token(desired_section, cmdbuf, 1, '|', sizeof desired_section);
358 safestrncpy(CC->download_desired_section, desired_section,
359 sizeof CC->download_desired_section);
360 CtdlOutputMsg(msgid, MT_SPEW_SECTION, 0, 1, 1, NULL, 0, NULL, NULL, NULL);
361}
362
363
364// message entry - mode 0 (normal)
365void cmd_ent0(char *entargs) {
366 int post = 0;
367 char recp[SIZ];
368 char cc[SIZ];
369 char bcc[SIZ];
370 char supplied_euid[128];
371 int anon_flag = 0;
372 int format_type = 0;
373 char newusername[256];
374 char newuseremail[256];
375 struct CtdlMessage *msg;
376 int anonymous = 0;
377 char errmsg[SIZ];
378 int err = 0;
379 struct recptypes *valid = NULL;
380 struct recptypes *valid_to = NULL;
381 struct recptypes *valid_cc = NULL;
382 struct recptypes *valid_bcc = NULL;
383 char subject[SIZ];
384 int subject_required = 0;
385 int do_confirm = 0;
386 long msgnum;
387 int i, j;
388 char buf[256];
389 int newuseremail_ok = 0;
390 char references[SIZ];
391 char *ptr;
392
394
395 post = extract_int(entargs, 0);
396 extract_token(recp, entargs, 1, '|', sizeof recp);
397 anon_flag = extract_int(entargs, 2);
398 format_type = extract_int(entargs, 3);
399 extract_token(subject, entargs, 4, '|', sizeof subject);
400 extract_token(newusername, entargs, 5, '|', sizeof newusername);
401 do_confirm = extract_int(entargs, 6);
402 extract_token(cc, entargs, 7, '|', sizeof cc);
403 extract_token(bcc, entargs, 8, '|', sizeof bcc);
404 switch(CC->room.QRdefaultview) {
405 case VIEW_NOTES:
406 case VIEW_WIKI:
407 extract_token(supplied_euid, entargs, 9, '|', sizeof supplied_euid);
408 break;
409 default:
410 supplied_euid[0] = 0;
411 break;
412 }
413 extract_token(newuseremail, entargs, 10, '|', sizeof newuseremail);
414 extract_token(references, entargs, 11, '|', sizeof references);
415 for (ptr=references; *ptr != 0; ++ptr) {
416 if (*ptr == '!') *ptr = '|';
417 }
418
419 /* first check to make sure the request is valid. */
420
422 errmsg,
423 sizeof errmsg,
424 NULL,
426 (!IsEmptyStr(references)) /* is this a reply? or a top-level post? */
427 );
428 if (err) {
429 cprintf("%d %s\n", err, errmsg);
430 return;
431 }
432
433 /* Check some other permission type things. */
434
435 if (IsEmptyStr(newusername)) {
436 strcpy(newusername, CC->user.fullname);
437 }
438 if ( (CC->user.axlevel < AxAideU)
439 && (strcasecmp(newusername, CC->user.fullname))
440 && (strcasecmp(newusername, CC->cs_inet_fn))
441 ) {
442 cprintf("%d You don't have permission to author messages as '%s'.\n",
444 newusername
445 );
446 return;
447 }
448
449 if (IsEmptyStr(newuseremail)) {
450 newuseremail_ok = 1;
451 }
452
453 if (!IsEmptyStr(newuseremail)) {
454 if (!strcasecmp(newuseremail, CC->cs_inet_email)) {
455 newuseremail_ok = 1;
456 }
457 else if (!IsEmptyStr(CC->cs_inet_other_emails)) {
458 j = num_tokens(CC->cs_inet_other_emails, '|');
459 for (i=0; i<j; ++i) {
460 extract_token(buf, CC->cs_inet_other_emails, i, '|', sizeof buf);
461 if (!strcasecmp(newuseremail, buf)) {
462 newuseremail_ok = 1;
463 }
464 }
465 }
466 }
467
468 if (!newuseremail_ok) {
469 cprintf("%d You don't have permission to author messages as '%s'.\n",
471 newuseremail
472 );
473 return;
474 }
475
476 CC->cs_flags |= CS_POSTING;
477
478 // In mailbox rooms we have to behave a little differently --
479 // make sure the user has specified at least one recipient. Then
480 // validate the recipient(s). We do this for the Mail> room, as
481 // well as any room which has the "Mailbox" view set - unless it
482 // is the DRAFTS room which does not require recipients.
483
484 if ( ( ( (CC->room.QRflags & QR_MAILBOX) && (!strcasecmp(&CC->room.QRname[11], MAILROOM)) )
485 || ( (CC->room.QRflags & QR_MAILBOX) && (CC->curr_view == VIEW_MAILBOX) )
486 ) && (strcasecmp(&CC->room.QRname[11], USERDRAFTROOM)) !=0 ) {
487 if (CC->user.axlevel < AxProbU) {
488 strcpy(recp, "sysop");
489 strcpy(cc, "");
490 strcpy(bcc, "");
491 }
492
493 valid_to = validate_recipients(recp, NULL, 0);
494 if (valid_to->num_error > 0) {
495 cprintf("%d %s\n", ERROR + NO_SUCH_USER, valid_to->errormsg);
496 free_recipients(valid_to);
497 return;
498 }
499
500 valid_cc = validate_recipients(cc, NULL, 0);
501 if (valid_cc->num_error > 0) {
502 cprintf("%d %s\n", ERROR + NO_SUCH_USER, valid_cc->errormsg);
503 free_recipients(valid_to);
504 free_recipients(valid_cc);
505 return;
506 }
507
508 valid_bcc = validate_recipients(bcc, NULL, 0);
509 if (valid_bcc->num_error > 0) {
510 cprintf("%d %s\n", ERROR + NO_SUCH_USER, valid_bcc->errormsg);
511 free_recipients(valid_to);
512 free_recipients(valid_cc);
513 free_recipients(valid_bcc);
514 return;
515 }
516
517 /* Recipient required, but none were specified */
518 if ( (valid_to->num_error < 0) && (valid_cc->num_error < 0) && (valid_bcc->num_error < 0) ) {
519 free_recipients(valid_to);
520 free_recipients(valid_cc);
521 free_recipients(valid_bcc);
522 cprintf("%d At least one recipient is required.\n", ERROR + NO_SUCH_USER);
523 return;
524 }
525
526 if (valid_to->num_internet + valid_cc->num_internet + valid_bcc->num_internet > 0) {
527 if (CtdlCheckInternetMailPermission(&CC->user)==0) {
528 cprintf("%d You do not have permission "
529 "to send Internet mail.\n",
531 free_recipients(valid_to);
532 free_recipients(valid_cc);
533 free_recipients(valid_bcc);
534 return;
535 }
536 }
537
538 if ( ( (valid_to->num_internet + valid_to->num_ignet + valid_cc->num_internet + valid_cc->num_ignet + valid_bcc->num_internet + valid_bcc->num_ignet) > 0)
539 && (CC->user.axlevel < AxNetU) ) {
540 cprintf("%d Higher access required for network mail.\n",
542 free_recipients(valid_to);
543 free_recipients(valid_cc);
544 free_recipients(valid_bcc);
545 return;
546 }
547
548 if ((RESTRICT_INTERNET == 1)
549 && (valid_to->num_internet + valid_cc->num_internet + valid_bcc->num_internet > 0)
550 && ((CC->user.flags & US_INTERNET) == 0)
551 && (!CC->internal_pgm)) {
552 cprintf("%d You don't have access to Internet mail.\n",
554 free_recipients(valid_to);
555 free_recipients(valid_cc);
556 free_recipients(valid_bcc);
557 return;
558 }
559
560 }
561
562 /* Is this a room which has anonymous-only or anonymous-option? */
563 anonymous = MES_NORMAL;
564 if (CC->room.QRflags & QR_ANONONLY) {
565 anonymous = MES_ANONONLY;
566 }
567 if (CC->room.QRflags & QR_ANONOPT) {
568 if (anon_flag == 1) { /* only if the user requested it */
569 anonymous = MES_ANONOPT;
570 }
571 }
572
573 if ((CC->room.QRflags & QR_MAILBOX) == 0) {
574 recp[0] = 0;
575 }
576
577 /* Recommend to the client that the use of a message subject is
578 * strongly recommended in this room, if either the SUBJECTREQ flag
579 * is set, or if there is one or more Internet email recipients.
580 */
581 if (CC->room.QRflags2 & QR2_SUBJECTREQ) subject_required = 1;
582 if ((valid_to) && (valid_to->num_internet > 0)) subject_required = 1;
583 if ((valid_cc) && (valid_cc->num_internet > 0)) subject_required = 1;
584 if ((valid_bcc) && (valid_bcc->num_internet > 0)) subject_required = 1;
585
586 /* If we're only checking the validity of the request, return
587 * success without creating the message.
588 */
589 if (post == 0) {
590 cprintf("%d %s|%d\n", CIT_OK,
591 ((valid_to != NULL) ? valid_to->display_recp : ""),
592 subject_required);
593 free_recipients(valid_to);
594 free_recipients(valid_cc);
595 free_recipients(valid_bcc);
596 return;
597 }
598
599 /* We don't need these anymore because we'll do it differently below */
600 free_recipients(valid_to);
601 free_recipients(valid_cc);
602 free_recipients(valid_bcc);
603
604 /* Read in the message from the client. */
605 if (do_confirm) {
606 cprintf("%d send message\n", START_CHAT_MODE);
607 } else {
608 cprintf("%d send message\n", SEND_LISTING);
609 }
610
611 msg = CtdlMakeMessage(&CC->user, recp, cc,
612 CC->room.QRname, anonymous, format_type,
613 newusername, newuseremail, subject,
614 ((!IsEmptyStr(supplied_euid)) ? supplied_euid : NULL),
615 NULL, references);
616
617 /* Put together one big recipients struct containing to/cc/bcc all in
618 * one. This is for the envelope.
619 */
620 char *all_recps = malloc(SIZ * 3);
621 strcpy(all_recps, recp);
622 if (!IsEmptyStr(cc)) {
623 if (!IsEmptyStr(all_recps)) {
624 strcat(all_recps, ",");
625 }
626 strcat(all_recps, cc);
627 }
628 if (!IsEmptyStr(bcc)) {
629 if (!IsEmptyStr(all_recps)) {
630 strcat(all_recps, ",");
631 }
632 strcat(all_recps, bcc);
633 }
634 if (!IsEmptyStr(all_recps)) {
635 valid = validate_recipients(all_recps, NULL, 0);
636 }
637 else {
638 valid = NULL;
639 }
640 free(all_recps);
641
642 // posting into a mailing list room? set the envelope from
643 // to the actual mail address so others get a valid reply-to-header.
644 if ((valid != NULL) && (valid->num_room == 1) && !IsEmptyStr(valid->recp_orgroom)) {
645 CM_SetField(msg, eenVelopeTo, valid->recp_orgroom, strlen(valid->recp_orgroom));
646 }
647
648 if (msg != NULL) {
649 msgnum = CtdlSubmitMsg(msg, valid, "");
650 if (do_confirm) {
651 cprintf("%ld\n", msgnum);
652
653 if (StrLength(CC->StatusMessage) > 0) {
654 cprintf("%s\n", ChrPtr(CC->StatusMessage));
655 }
656 else if (msgnum >= 0L) {
657 client_write(HKEY("Message accepted.\n"));
658 }
659 else {
660 client_write(HKEY("Internal error.\n"));
661 }
662
663 if (!CM_IsEmpty(msg, eExclusiveID)) {
664 cprintf("%s\n", msg->cm_fields[eExclusiveID]);
665 } else {
666 cprintf("\n");
667 }
668 cprintf("000\n");
669 }
670
671 CM_Free(msg);
672 }
673 if (valid != NULL) {
674 free_recipients(valid);
675 }
676 return;
677}
678
679
680// Delete message from current room
681void cmd_dele(char *args) {
682 int num_deleted;
683 int i;
684 char msgset[SIZ];
685 char msgtok[32];
686 long *msgs;
687 int num_msgs = 0;
688
689 extract_token(msgset, args, 0, '|', sizeof msgset);
690 num_msgs = num_tokens(msgset, ',');
691 if (num_msgs < 1) {
692 cprintf("%d Nothing to do.\n", CIT_OK);
693 return;
694 }
695
697 cprintf("%d Higher access required.\n",
699 return;
700 }
701
702 /*
703 * Build our message set to be moved/copied
704 */
705 msgs = malloc(num_msgs * sizeof(long));
706 for (i=0; i<num_msgs; ++i) {
707 extract_token(msgtok, msgset, i, ',', sizeof msgtok);
708 msgs[i] = atol(msgtok);
709 }
710
711 num_deleted = CtdlDeleteMessages(CC->room.QRname, msgs, num_msgs, "");
712 free(msgs);
713
714 if (num_deleted) {
715 cprintf("%d %d message%s deleted.\n", CIT_OK,
716 num_deleted, ((num_deleted != 1) ? "s" : ""));
717 } else {
718 cprintf("%d Message not found.\n", ERROR + MESSAGE_NOT_FOUND);
719 }
720}
721
722
723// move or copy a message to another room
724void cmd_move(char *args) {
725 char msgset[SIZ];
726 char msgtok[32];
727 long *msgs;
728 int num_msgs = 0;
729
730 char targ[ROOMNAMELEN];
731 struct ctdlroom qtemp;
732 int err;
733 int is_copy = 0;
734 int ra;
735 int permit = 0;
736 int i;
737
738 extract_token(msgset, args, 0, '|', sizeof msgset);
739 num_msgs = num_tokens(msgset, ',');
740 if (num_msgs < 1) {
741 cprintf("%d Nothing to do.\n", CIT_OK);
742 return;
743 }
744
745 extract_token(targ, args, 1, '|', sizeof targ);
746 convert_room_name_macros(targ, sizeof targ);
747 targ[ROOMNAMELEN - 1] = 0;
748 is_copy = extract_int(args, 2);
749
750 if (CtdlGetRoom(&qtemp, targ) != 0) {
751 cprintf("%d '%s' does not exist.\n", ERROR + ROOM_NOT_FOUND, targ);
752 return;
753 }
754
755 if (!strcasecmp(qtemp.QRname, CC->room.QRname)) {
756 cprintf("%d Source and target rooms are the same.\n", ERROR + ALREADY_EXISTS);
757 return;
758 }
759
760 CtdlGetUser(&CC->user, CC->curr_user);
761 CtdlRoomAccess(&qtemp, &CC->user, &ra, NULL);
762
763 /* Check for permission to perform this operation.
764 * Remember: "CC->room" is source, "qtemp" is target.
765 */
766 permit = 0;
767
768 /* Admins can move/copy */
769 if (CC->user.axlevel >= AxAideU) permit = 1;
770
771 /* Room aides can move/copy */
772 if (CC->user.usernum == CC->room.QRroomaide) permit = 1;
773
774 /* Permit move/copy from personal rooms */
775 if ((CC->room.QRflags & QR_MAILBOX)
776 && (qtemp.QRflags & QR_MAILBOX)) permit = 1;
777
778 /* Permit only copy from public to personal room */
779 if ( (is_copy)
780 && (!(CC->room.QRflags & QR_MAILBOX))
781 && (qtemp.QRflags & QR_MAILBOX)) permit = 1;
782
783 /* Permit message removal from collaborative delete rooms */
784 if (CC->room.QRflags2 & QR2_COLLABDEL) permit = 1;
785
786 /* Users allowed to post into the target room may move into it too. */
787 if ((CC->room.QRflags & QR_MAILBOX) &&
788 (qtemp.QRflags & UA_POSTALLOWED)) permit = 1;
789
790 /* User must have access to target room */
791 if (!(ra & UA_KNOWN)) permit = 0;
792
793 if (!permit) {
794 cprintf("%d Higher access required.\n",
796 return;
797 }
798
799 /*
800 * Build our message set to be moved/copied
801 */
802 msgs = malloc(num_msgs * sizeof(long));
803 for (i=0; i<num_msgs; ++i) {
804 extract_token(msgtok, msgset, i, ',', sizeof msgtok);
805 msgs[i] = atol(msgtok);
806 }
807
808 /*
809 * Do the copy
810 */
811 err = CtdlSaveMsgPointersInRoom(targ, msgs, num_msgs, 1, NULL, 0);
812 if (err != 0) {
813 cprintf("%d Cannot store message(s) in %s: error %d\n",
814 err, targ, err);
815 free(msgs);
816 return;
817 }
818
819 /* Now delete the message from the source room,
820 * if this is a 'move' rather than a 'copy' operation.
821 */
822 if (is_copy == 0) {
823 CtdlDeleteMessages(CC->room.QRname, msgs, num_msgs, "");
824 }
825 free(msgs);
826
827 cprintf("%d Message(s) %s.\n", CIT_OK, (is_copy ? "copied" : "moved") );
828}
829
830
831/*****************************************************************************/
832/* MODULE INITIALIZATION STUFF */
833/*****************************************************************************/
834CTDL_MODULE_INIT(ctdl_message)
835{
836 if (!threading) {
837
838 CtdlRegisterProtoHook(cmd_msgs, "MSGS", "Output a list of messages in the current room");
839 CtdlRegisterProtoHook(cmd_msg0, "MSG0", "Output a message in plain text format");
840 CtdlRegisterProtoHook(cmd_msg2, "MSG2", "Output a message in RFC822 format");
841 CtdlRegisterProtoHook(cmd_msg4, "MSG4", "Output a message in the client's preferred format");
842 CtdlRegisterProtoHook(cmd_msgp, "MSGP", "Select preferred format for MSG4 output");
843 CtdlRegisterProtoHook(cmd_opna, "OPNA", "Open an attachment for download");
844 CtdlRegisterProtoHook(cmd_dlat, "DLAT", "Download an attachment");
845 CtdlRegisterProtoHook(cmd_ent0, "ENT0", "Enter a message");
846 CtdlRegisterProtoHook(cmd_dele, "DELE", "Delete a message");
847 CtdlRegisterProtoHook(cmd_move, "MOVE", "Move or copy a message to another room");
848 }
849
850 /* return our Subversion id for the Log */
851 return "ctdl_message";
852}
#define ROOMNAMELEN
Definition: citadel.h:56
#define MES_ANONONLY
Definition: citadel.h:136
#define MES_NORMAL
Definition: citadel.h:135
#define MES_ANONOPT
Definition: citadel.h:137
char * CtdlGetConfigStr(char *key)
Definition: config.c:384
int CtdlGetConfigInt(char *key)
Definition: config.c:417
#define CC
Definition: context.h:140
int CtdlAccessCheck(int)
Definition: user_ops.c:387
int CtdlGetRoom(struct ctdlroom *qrbuf, const char *room_name)
Definition: room_ops.c:342
#define RESTRICT_INTERNET
Definition: ctdl_module.h:264
void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, int *result, int *view)
Definition: room_ops.c:121
@ ac_logged_in_or_guest
Definition: ctdl_module.h:243
int CtdlGetUser(struct ctdluser *usbuf, char *name)
Definition: user_ops.c:75
void CtdlRegisterProtoHook(void(*handler)(char *), char *cmd, char *desc)
#define CTDL_MODULE_INIT(module_name)
Definition: ctdl_module.h:50
struct recptypes * validate_recipients(char *supplied_recipients, const char *RemoteIdentifier, int Flags)
void free_recipients(struct recptypes *valid)
#define CIT_OK
Definition: ipcdef.h:6
#define QR2_SUBJECTREQ
Definition: ipcdef.h:58
#define LISTING_FOLLOWS
Definition: ipcdef.h:5
#define HIGHER_ACCESS_REQUIRED
Definition: ipcdef.h:23
#define QR_ANONOPT
Definition: ipcdef.h:49
#define ROOM_NOT_FOUND
Definition: ipcdef.h:31
#define START_CHAT_MODE
Definition: ipcdef.h:12
#define QR_ANONONLY
Definition: ipcdef.h:48
#define QR2_COLLABDEL
Definition: ipcdef.h:57
#define CMD_NOT_SUPPORTED
Definition: ipcdef.h:18
#define QR_MAILBOX
Definition: ipcdef.h:53
#define ERROR
Definition: ipcdef.h:9
#define SEND_LISTING
Definition: ipcdef.h:8
#define ALREADY_EXISTS
Definition: ipcdef.h:33
#define UA_KNOWN
Definition: ipcdef.h:79
#define MESSAGE_NOT_FOUND
Definition: ipcdef.h:34
#define NO_SUCH_USER
Definition: ipcdef.h:29
#define UA_POSTALLOWED
Definition: ipcdef.h:83
#define US_INTERNET
Definition: ipcdef.h:72
void CM_Free(struct CtdlMessage *msg)
Definition: msgbase.c:310
int CtdlOutputMsg(long msg_num, int mode, int headers_only, int do_proto, int crlf, char *section, int flags, char **Author, char **Address, char **MessageID)
Definition: msgbase.c:1481
struct CtdlMessage * CtdlMakeMessage(struct ctdluser *author, char *recipient, char *recp_cc, char *room, int type, int format_type, char *fake_name, char *my_email, char *subject, char *supplied_euid, char *preformatted_text, char *references)
Definition: msgbase.c:3060
int CtdlForEachMessage(int mode, long ref, char *search_string, char *content_type, struct CtdlMessage *compare, ForEachMsgCallback CallBack, void *userdata)
Definition: msgbase.c:626
struct CtdlMessage * CtdlFetchMessage(long msgnum, int with_body)
Definition: msgbase.c:1135
int CM_IsEmpty(struct CtdlMessage *Msg, eMsgField which)
Definition: msgbase.c:137
int CtdlDeleteMessages(const char *room_name, long *dmsgnums, int num_dmsgnums, char *content_type)
Definition: msgbase.c:3240
long CtdlSubmitMsg(struct CtdlMessage *msg, struct recptypes *recps, const char *force)
Definition: msgbase.c:2603
void CM_SetField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long length)
Definition: msgbase.c:142
int GetFieldFromMnemonic(eMsgField *f, const char *c)
Definition: msgbase.c:78
int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs, int do_repl_check, struct CtdlMessage *supplied_msg, int suppress_refcount_adj)
Definition: msgbase.c:2236
void(* ForEachMsgCallback)(long MsgNumber, void *UserData)
Definition: msgbase.h:90
#define HEADERS_ALL
Definition: msgbase.h:39
@ MSG_HDRS_BRIEFFILTER
Definition: msgbase.h:21
@ MSG_HDRS_THREADS
Definition: msgbase.h:22
@ MSG_HDRS_EUID
Definition: msgbase.h:20
@ MSG_HDRS_ALL
Definition: msgbase.h:19
@ MSG_HDRS_BRIEF
Definition: msgbase.h:18
#define CM_KEY(Message, Which)
Definition: msgbase.h:126
@ MSGS_FIRST
Definition: msgbase.h:9
@ MSGS_NEW
Definition: msgbase.h:8
@ MSGS_SEARCH
Definition: msgbase.h:13
@ MSGS_ALL
Definition: msgbase.h:6
@ MSGS_GT
Definition: msgbase.h:11
@ MSGS_OLD
Definition: msgbase.h:7
@ MSGS_LAST
Definition: msgbase.h:10
@ MSGS_LT
Definition: msgbase.h:14
void * malloc(size_t)
void free(void *)
int CtdlDoIHavePermissionToDeleteMessagesFromThisRoom(void)
Definition: room_ops.c:109
void convert_room_name_macros(char *towhere, size_t maxlen)
Definition: room_ops.c:876
int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf, size_t n, const char *RemoteIdentifier, PostType PostPublic, int is_reply)
Definition: room_ops.c:47
@ POST_LOGGED_IN
Definition: room_ops.h:13
void do_confirm(char *token)
Definition: serv_listsub.c:268
void cmd_dele(char *args)
char * msgkeys[]
Definition: msgbase.c:37
void cmd_msg2(char *cmdbuf)
void simple_listing(long msgnum, void *userdata)
Definition: serv_messages.c:26
void headers_listing(long msgnum, void *userdata)
Definition: serv_messages.c:32
void cmd_msg4(char *cmdbuf)
void cmd_msgp(char *cmdbuf)
void cmd_msgs(char *cmdbuf)
struct _msg_filter msg_filter
void headers_euid(long msgnum, void *userdata)
void cmd_msg0(char *cmdbuf)
void cmd_dlat(char *cmdbuf)
void cmd_opna(char *cmdbuf)
void cmd_ent0(char *entargs)
void cmd_move(char *args)
void headers_brief_filter(long msgnum, void *userdata)
Definition: serv_messages.c:97
enum _MsgField eMsgField
#define CTDLMESSAGE_MAGIC
Definition: server.h:42
@ eExclusiveID
Definition: server.h:309
@ eWeferences
Definition: server.h:322
@ eenVelopeTo
Definition: server.h:321
@ emessageId
Definition: server.h:311
@ erFc822Addr
Definition: server.h:310
@ eAuthor
Definition: server.h:307
@ eTimestamp
Definition: server.h:319
@ eMsgSubject
Definition: server.h:320
#define CS_POSTING
Definition: server.h:112
@ MT_CITADEL
Definition: server.h:166
@ MT_DOWNLOAD
Definition: server.h:169
@ MT_SPEW_SECTION
Definition: server.h:170
@ MT_MIME
Definition: server.h:168
@ MT_RFC822
Definition: server.h:167
char * cm_fields[256]
Definition: server.h:37
StrBuf * buffer
Definition: serv_messages.c:93
HashPos * p
Definition: serv_messages.c:92
HashList * Filter
Definition: serv_messages.c:91
char QRname[128]
Definition: citadel.h:108
unsigned QRflags
Definition: citadel.h:113
char * display_recp
Definition: server.h:59
int num_internet
Definition: server.h:50
int num_ignet
Definition: server.h:51
int num_room
Definition: server.h:52
char * recp_orgroom
Definition: server.h:58
int num_error
Definition: server.h:53
char * errormsg
Definition: server.h:54
#define MAILROOM
Definition: sysconfig.h:61
#define USERDRAFTROOM
Definition: sysconfig.h:69
#define SIZ
Definition: sysconfig.h:33
void cprintf(const char *format,...)
Definition: sysdep.c:381
int client_getln(char *buf, int bufsize)
Definition: sysdep.c:548
int client_write(const char *buf, int nbytes)
Definition: sysdep.c:307
void buffer_output(void)
Definition: sysdep.c:267
void unbuffer_output(void)
Definition: sysdep.c:276
void cputbuf(const StrBuf *Buf)
Definition: sysdep.c:374
int CtdlCheckInternetMailPermission(struct ctdluser *who)
Definition: user_ops.c:365