/*
* This program was hacked by Harald Kipp using a source
* written by Eric S. Raymond.
*
* Bug reports related to THIS modified version should be sent to
*
* harald@os2point.ping.de
* harald@haport.sesam.com
* Fido: 2:2448/434
*
* You may freely copy or redistribute this software. However,
* this may not apply to any part of it, if otherwise noted.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <lprintf.h>
#include <history.h>
#include <active.h>
#include "config.h"
#include "chanco.h"
/*
* CANCEL message-id
*/
void c_cancel(int argc, char **argv)
{
char artpath[_MAX_PATH];
char artlist[BUFSIZ];
char *cp, *cp1, *cp2;
char *group;
long artnum, lomsg, himsg;
char mc;
if (argc < 2) {
lprintf("cancel: Not enough arguments.");
return;
}
lprintf("Cancel %s", argv[1]);
/*
* This call will delete the history entry and
* fill artlist with group:num[,group:num]
*/
cp = delhistart(cfg.historyfile, argv[1], artlist);
if(*cp == '\0')
lprintf("Article to cancel not found");
cp2 = strchr(strcpy(artpath, cfg.newsdir), '\0');
*cp2++ = '\\';
/*
* cp walks along our newsgroup list filled by delhistart
* cp2 is fixed at the end of news home directory path
* cp1 appends the article path to cp2
*/
while(*cp) {
group = cp;
artnum = 0;
cp1 = cp2;
while(*cp && *cp != ' ' && *cp != '\t' && *cp != ',') {
if(*cp == '.' || *cp == ':') {
*cp1++ = '\\';
if(*cp == ':') {
*cp = '\0';
artnum = atol(cp + 1);
}
}
else
*cp1++ = *cp;
cp++;
}
*cp1 = '\0';
if(artnum) {
/* Todo: Active should be locked */
mc = find_active(cfg.activefile, group, &lomsg, &himsg);
/* Todo: We might look for approval on moderated groups */
if(mc) {
/*
* Update active file if artnum is at a boundary
*/
if(lomsg == artnum) {
upd_active(group, -1, 0);
save_active(cfg.activefile);
}
else if(himsg == artnum) {
upd_active(group, 0, -1);
save_active(cfg.activefile);
}
}
/*
* Delete article file
*/
if(unlink(artpath))
lperror(artpath);
}
while(*cp && (*cp == ' ' || *cp == '\t' || *cp == ','))
cp++;
}
}