summaryrefslogtreecommitdiffstats
path: root/util/bbsmail.c
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-11-02 19:02:32 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-11-02 19:02:32 +0800
commit87e05ea3f3ac90f87736bff8141e245bf5572595 (patch)
treeae4361e2b8e50b3f3c73af08ecd261a6a4e1a49d /util/bbsmail.c
parent4ccaf508da7e628542906ccaf30f194b71cae255 (diff)
downloadpttbbs-87e05ea3f3ac90f87736bff8141e245bf5572595.tar
pttbbs-87e05ea3f3ac90f87736bff8141e245bf5572595.tar.gz
pttbbs-87e05ea3f3ac90f87736bff8141e245bf5572595.tar.bz2
pttbbs-87e05ea3f3ac90f87736bff8141e245bf5572595.tar.lz
pttbbs-87e05ea3f3ac90f87736bff8141e245bf5572595.tar.xz
pttbbs-87e05ea3f3ac90f87736bff8141e245bf5572595.tar.zst
pttbbs-87e05ea3f3ac90f87736bff8141e245bf5572595.zip
strip_ansi title
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@549 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/bbsmail.c')
-rw-r--r--util/bbsmail.c53
1 files changed, 43 insertions, 10 deletions
diff --git a/util/bbsmail.c b/util/bbsmail.c
index 54e4dc47..7c671418 100644
--- a/util/bbsmail.c
+++ b/util/bbsmail.c
@@ -1,4 +1,4 @@
-/* $Id: bbsmail.c,v 1.4 2002/07/01 08:03:55 in2 Exp $ */
+/* $Id: bbsmail.c,v 1.5 2002/11/02 11:02:32 in2 Exp $ */
#define _BBS_UTIL_C_
#include "bbs.h"
@@ -11,6 +11,40 @@ extern char *notitle[], *nofrom[], *nocont[];
extern userec_t xuser;
+int
+strip_ansi(char *buf, char *str, int mode)
+{
+ register int ansi, count = 0;
+
+ for (ansi = 0; *str /* && *str != '\n' */ ; str++) {
+ if (*str == 27) {
+ if (mode) {
+ if (buf)
+ *buf++ = *str;
+ count++;
+ }
+ ansi = 1;
+ } else if (ansi && strchr("[;1234567890mfHABCDnsuJKc=n", *str)) {
+ if ((mode == NO_RELOAD && !strchr("c=n", *str)) ||
+ (mode == ONLY_COLOR && strchr("[;1234567890m", *str))) {
+ if (buf)
+ *buf++ = *str;
+ count++;
+ }
+ if (strchr("mHn ", *str))
+ ansi = 0;
+ } else {
+ ansi = 0;
+ if (buf)
+ *buf++ = *str;
+ count++;
+ }
+ }
+ if (buf)
+ *buf = '\0';
+ return count;
+}
+
int mailalertuid(int tuid)
{
userinfo_t *uentp=NULL;
@@ -46,7 +80,7 @@ mail2bbs(userid)
{
int uid;
fileheader_t mymail;
- char genbuf[256], title[80], sender[80], filename[80], *ip, *ptr;
+ char genbuf[512], title[512], sender[512], filename[512], *ip, *ptr;
time_t tmp_time;
struct stat st;
FILE *fout;
@@ -107,13 +141,13 @@ mail2bbs(userid)
strtok(genbuf, " \t\n\r");
ptr= strtok(NULL, " \t\n\r");
if(ptr)
- strcpy(sender, ptr);
+ strlcpy(sender, ptr, sizeof(sender));
}
continue;
}
if (!strncmp(genbuf, "Subject: ", 9))
{
- strcpy(title, genbuf + 9);
+ strlcpy(title, genbuf + 9, sizeof(title));
continue;
}
if (genbuf[0] == '\n')
@@ -186,13 +220,13 @@ mail2bbs(userid)
mailog(genbuf);
/* append the record to the MAIL control file */
-
- strcpy(mymail.title, title);
+ strip_ansi(title, title, 0);
+ strlcpy(mymail.title, title, sizeof(mymail.title));
if (strtok(sender, " .@\t\n\r"))
strcat(sender, ".");
sender[IDLEN + 1] = '\0';
- strcpy(mymail.owner, sender);
+ strlcpy(mymail.owner, sender, sizeof(mymail.owner));
sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", userid[0], userid);
mailalertuid(uid);
@@ -203,7 +237,7 @@ mail2bbs(userid)
int
main(int argc, char* argv[])
{
- char receiver[256];
+ char receiver[512];
chdir(BBSHOME);
/* argv[1] is userid in bbs */
@@ -216,8 +250,7 @@ main(int argc, char* argv[])
(void) setgid(BBSGID);
(void) setuid(BBSUID);
- if(passwd_mmap()) exit(-1);
- strcpy(receiver, argv[1]);
+ strlcpy(receiver, argv[1], sizeof(receiver));
strtok(receiver,".");
if (mail2bbs(receiver))