This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-mbse/mbsebbs/msgutil.c

323 lines
8.2 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
2001-11-04 12:44:59 +00:00
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: Utilities for message handling.
*
*****************************************************************************
2005-08-13 19:51:32 +00:00
* Copyright (C) 1997-2005
2001-08-17 05:46:24 +00:00
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
2003-08-15 20:05:34 +00:00
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
2001-08-17 05:46:24 +00:00
*****************************************************************************/
2002-06-30 12:48:44 +00:00
#include "../config.h"
2004-02-21 17:22:00 +00:00
#include "../lib/mbselib.h"
2001-08-17 05:46:24 +00:00
#include "../lib/mbse.h"
2002-01-07 19:16:03 +00:00
#include "../lib/users.h"
2001-08-17 05:46:24 +00:00
#include "../lib/msgtext.h"
#include "../lib/msg.h"
#include "oneline.h"
#include "msgutil.h"
int BaseWrite = FALSE;
2003-09-14 12:24:18 +00:00
int NewMessages = FALSE;
2001-08-17 05:46:24 +00:00
static char *wdays[]={(char *)"Sun",(char *)"Mon",(char *)"Tue",(char *)"Wed",
(char *)"Thu",(char *)"Fri",(char *)"Sat"};
static char *months[]={(char *)"Jan",(char *)"Feb",(char *)"Mar",
(char *)"Apr",(char *)"May",(char *)"Jun",
(char *)"Jul",(char *)"Aug",(char *)"Sep",
(char *)"Oct",(char *)"Nov",(char *)"Dec"};
char *rfcdate(time_t now)
{
2003-05-10 11:51:43 +00:00
static char buf[40];
struct tm ptm, gtm;
char sign;
int hr, min;
2005-10-11 20:49:41 +00:00
int offset;
2003-05-10 11:51:43 +00:00
if (!now)
now = time(NULL);
ptm = *localtime(&now);
/*
* To get the timezone, compare localtime with GMT.
*/
gtm = *gmtime(&now);
/*
* Assume we are never more than 24 hours away.
*/
offset = gtm.tm_yday - ptm.tm_yday;
if (offset > 1)
offset = -24;
else if (offset < -1)
offset = 24;
else
offset *= 24;
/*
* Scale in the hours and minutes; ignore seconds.
*/
offset += gtm.tm_hour - ptm.tm_hour;
offset *= 60;
offset += gtm.tm_min - ptm.tm_min;
if (offset <= 0) {
sign='+';
offset=-offset;
} else
sign='-';
hr=offset/60L;
min=offset%60L;
2005-08-29 10:59:47 +00:00
snprintf(buf,40,"%s, %02d %s %04d %02d:%02d:%02d %c%02d%02d",
2001-08-17 05:46:24 +00:00
wdays[gtm.tm_wday],gtm.tm_mday,months[gtm.tm_mon],
gtm.tm_year+1900,gtm.tm_hour,gtm.tm_min,gtm.tm_sec,
sign,hr,min);
2003-05-10 11:51:43 +00:00
return(buf);
2001-08-17 05:46:24 +00:00
}
/*
* Open specified message base for read or write.
*/
int Open_Msgbase(char *Base, int Mode)
{
2003-05-10 11:51:43 +00:00
BaseWrite = FALSE;
2003-09-14 12:24:18 +00:00
NewMessages = FALSE;
2001-08-17 05:46:24 +00:00
2003-05-10 11:51:43 +00:00
if (!Msg_Open(Base))
return FALSE;
2001-08-17 05:46:24 +00:00
2003-05-10 11:51:43 +00:00
if (Mode != 'w')
return TRUE;
2001-08-17 05:46:24 +00:00
2003-05-10 11:51:43 +00:00
if (!Msg_Lock(30L)) {
Msg_Close();
return FALSE;
}
2001-08-17 05:46:24 +00:00
2003-05-10 11:51:43 +00:00
BaseWrite = TRUE;
return TRUE;
2001-08-17 05:46:24 +00:00
}
/*
* Close current messagebase.
*/
2003-09-14 12:24:18 +00:00
void Close_Msgbase(char *Base)
2001-08-17 05:46:24 +00:00
{
2003-09-14 12:24:18 +00:00
int rc;
Syslog('b', "Close_Msgbase(%s) BaseWrite=%s NewMessages=%s", Base, BaseWrite?"TRUE":"FALSE", NewMessages?"TRUE":"FALSE");
2003-05-10 11:51:43 +00:00
if (BaseWrite) {
Msg_UnLock();
BaseWrite = FALSE;
2003-09-14 12:24:18 +00:00
if (NewMessages) {
rc = Msg_Link(Base, TRUE, CFG.slow_util);
if (rc != -1)
Syslog('+', "Linked %d message%s", rc, (rc != 1) ? "s":"");
else
Syslog('+', "Could not link messages");
}
2003-05-10 11:51:43 +00:00
}
Msg_Close();
2001-08-17 05:46:24 +00:00
}
void Add_Headkludges(faddr *dest, int IsReply)
{
2005-08-13 21:54:29 +00:00
char *temp;
2005-10-11 20:49:41 +00:00
unsigned int crc = -1;
2003-05-10 11:51:43 +00:00
time_t tt;
faddr *Node;
temp = calloc(128, sizeof(char));
switch (msgs.Type) {
case LOCALMAIL: Msg.Localmail = TRUE;
break;
case NETMAIL: Msg.Netmail = TRUE;
2005-08-29 10:59:47 +00:00
snprintf(Msg.FromAddress, 101, "%s", aka2str(msgs.Aka));
snprintf(Msg.ToAddress, 101, "%s", ascfnode(dest, 0x1f));
2003-05-10 11:51:43 +00:00
if (msgs.Aka.point) {
2005-08-29 10:59:47 +00:00
snprintf(temp, 128, "\001FMPT %d", msgs.Aka.point);
2003-05-10 11:51:43 +00:00
MsgText_Add2(temp);
}
if (dest->point) {
2005-08-29 10:59:47 +00:00
snprintf(temp, 128, "\001TOPT %d", dest->point);
2003-05-10 11:51:43 +00:00
MsgText_Add2(temp);
}
2005-08-29 10:59:47 +00:00
snprintf(temp, 128, "\001INTL %d:%d/%d %d:%d/%d", dest->zone, dest->net,
2003-05-10 11:51:43 +00:00
dest->node, msgs.Aka.zone, msgs.Aka.net, msgs.Aka.node);
MsgText_Add2(temp);
break;
case LIST: Msg.Echomail = TRUE;
2005-08-29 10:59:47 +00:00
snprintf(Msg.FromAddress, 101, "%s", aka2str(msgs.Aka));
2003-05-10 11:51:43 +00:00
break;
case ECHOMAIL: Msg.Echomail = TRUE;
2005-08-29 10:59:47 +00:00
snprintf(Msg.FromAddress, 101, "%s", aka2str(msgs.Aka));
2003-05-10 11:51:43 +00:00
break;
case NEWS: /*
* Header style is the same as GoldED does.
*/
Msg.News = TRUE;
2005-08-29 10:59:47 +00:00
snprintf(temp, 101, "\001Date: %s", rfcdate(Msg.Written));
2003-05-10 11:51:43 +00:00
MsgText_Add2(temp);
Node = fido2faddr(msgs.Aka);
2005-08-29 10:59:47 +00:00
snprintf(temp, 101, "\001From: %s", Msg.From);
2003-05-10 11:51:43 +00:00
MsgText_Add2(temp);
2005-08-29 10:59:47 +00:00
snprintf(temp, 101, "\001Subject: %s", Msg.Subject);
2003-05-10 11:51:43 +00:00
MsgText_Add2(temp);
2005-08-29 10:59:47 +00:00
snprintf(temp, 101, "\001Sender: %s", Msg.From);
2003-05-10 11:51:43 +00:00
MsgText_Add2(temp);
tidy_faddr(Node);
MsgText_Add2((char *)"\001To: All");
MsgText_Add2((char *)"\001MIME-Version: 1.0");
2005-08-13 19:51:32 +00:00
if (exitinfo.Charset != FTNC_NONE) {
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "\001Content-Type: text/plain; charset=%s", getrfcchrs(exitinfo.Charset));
2005-08-13 19:51:32 +00:00
} else if (msgs.Charset != FTNC_NONE) {
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "\001Content-Type: text/plain; charset=%s", getrfcchrs(msgs.Charset));
2005-08-13 19:51:32 +00:00
} else {
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "\001Content-Type: text/plain; charset=iso8859-1");
2005-08-13 19:51:32 +00:00
}
MsgText_Add2(temp);
2003-05-10 11:51:43 +00:00
MsgText_Add2((char *)"\001Content-Transfer-Encoding: 8bit");
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "\001X-Mailreader: MBSE BBS %s", VERSION);
2003-05-10 11:51:43 +00:00
MsgText_Add2(temp);
break;
}
2005-04-03 14:12:12 +00:00
/*
* Set the right charset kludge
*/
if (exitinfo.Charset != FTNC_NONE) {
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "\001CHRS: %s", getftnchrs(exitinfo.Charset));
2005-04-03 14:12:12 +00:00
} else if (msgs.Charset != FTNC_NONE) {
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "\001CHRS: %s", getftnchrs(msgs.Charset));
2004-02-23 15:46:32 +00:00
} else {
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "\001CHRS: %s", getftnchrs(FTNC_LATIN_1));
2004-02-23 15:46:32 +00:00
}
MsgText_Add2(temp);
2005-10-11 20:49:41 +00:00
snprintf(temp, PATH_MAX, "\001MSGID: %s %08x", aka2str(msgs.Aka), sequencer());
2003-05-10 11:51:43 +00:00
MsgText_Add2(temp);
Msg.MsgIdCRC = upd_crc32(temp, crc, strlen(temp));
if (IsReply) {
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "\001REPLY: %s", Msg.Replyid);
2001-08-17 05:46:24 +00:00
MsgText_Add2(temp);
2003-05-10 11:51:43 +00:00
crc = -1;
Msg.ReplyCRC = upd_crc32(temp, crc, strlen(temp));
} else
Msg.ReplyCRC = 0xffffffff;
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "\001PID: MBSE-BBS %s (%s-%s)", VERSION, OsName(), OsCPU());
2003-05-10 11:51:43 +00:00
MsgText_Add2(temp);
tt = time(NULL);
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "\001TZUTC: %s", gmtoffset(tt));
2003-05-10 11:51:43 +00:00
MsgText_Add2(temp);
free(temp);
2001-08-17 05:46:24 +00:00
}
/*
* Add bottom message kludges. The flag Quote is false if this is called
* from Offline Reader, the user then may or may have not added a quote.
2002-07-03 21:16:23 +00:00
* The QWK upload may set HasTear if the client already uploaded a tearline.
2001-08-17 05:46:24 +00:00
*/
2002-07-03 21:16:23 +00:00
void Add_Footkludges(int Quote, char *tear, int HasTear)
2001-08-17 05:46:24 +00:00
{
2003-05-10 11:51:43 +00:00
char *temp, *aka;
FILE *fp;
temp = calloc(PATH_MAX, sizeof(char));
aka = calloc(32, sizeof(char));
/*
* If Quote (message entered at the bbs) we append a signature.
*/
if (Quote) {
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "%s/%s/.signature", CFG.bbs_usersdir, exitinfo.Name);
2003-05-10 11:51:43 +00:00
if ((fp = fopen(temp, "r"))) {
MsgText_Add2((char *)"");
while (fgets(temp, 80, fp)) {
Striplf(temp);
MsgText_Add2(temp);
2001-11-04 12:44:59 +00:00
}
2003-05-10 11:51:43 +00:00
fclose(fp);
MsgText_Add2((char *)"");
2001-11-04 12:44:59 +00:00
}
2003-05-10 11:51:43 +00:00
}
2001-11-04 12:44:59 +00:00
2003-05-10 11:51:43 +00:00
if (msgs.Quotes && Quote) {
2005-08-29 10:59:47 +00:00
snprintf(temp, 81, "... %s", Oneliner_Get());
2003-05-10 11:51:43 +00:00
MsgText_Add2(temp);
MsgText_Add2((char *)"");
}
/*
* The offline reader may override the tearline
*/
if (!HasTear) {
if (tear == NULL) {
MsgText_Add2(TearLine());
} else {
2005-08-29 10:59:47 +00:00
snprintf(temp, 81, "--- %s", tear);
2003-05-10 11:51:43 +00:00
MsgText_Add2(temp);
2001-08-17 05:46:24 +00:00
}
2003-05-10 11:51:43 +00:00
}
2002-07-01 19:31:15 +00:00
2003-05-10 11:51:43 +00:00
if ((msgs.Type == ECHOMAIL) || (msgs.Type == LIST)) {
if (msgs.Aka.point)
2005-08-29 10:59:47 +00:00
snprintf(aka, 32, "(%d:%d/%d.%d)", msgs.Aka.zone, msgs.Aka.net, msgs.Aka.node, msgs.Aka.point);
2003-05-10 11:51:43 +00:00
else
2005-08-29 10:59:47 +00:00
snprintf(aka, 32, "(%d:%d/%d)", msgs.Aka.zone, msgs.Aka.net, msgs.Aka.node);
2001-08-17 05:46:24 +00:00
2003-05-10 11:51:43 +00:00
if (strlen(msgs.Origin))
2005-08-29 10:59:47 +00:00
snprintf(temp, 81, " * Origin: %s %s", msgs.Origin, aka);
2003-05-10 11:51:43 +00:00
else
2005-08-29 10:59:47 +00:00
snprintf(temp, 81, " * Origin: %s %s", CFG.origin, aka);
2003-05-10 11:51:43 +00:00
MsgText_Add2(temp);
}
2001-08-17 05:46:24 +00:00
2003-05-10 11:51:43 +00:00
free(aka);
free(temp);
2003-09-14 12:24:18 +00:00
NewMessages = TRUE;
2001-08-17 05:46:24 +00:00
}