summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-02-14 18:20:39 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-02-14 18:20:39 +0800
commit162a59f51f60fa7fc589ef2f75625fad7f024dea (patch)
treefe99a4ec494d9d98496ccd67b41e053d7637ff65
parent69235ab6f7b279ff15443448b23b6944931c0275 (diff)
downloadpttbbs-162a59f51f60fa7fc589ef2f75625fad7f024dea.tar
pttbbs-162a59f51f60fa7fc589ef2f75625fad7f024dea.tar.gz
pttbbs-162a59f51f60fa7fc589ef2f75625fad7f024dea.tar.bz2
pttbbs-162a59f51f60fa7fc589ef2f75625fad7f024dea.tar.lz
pttbbs-162a59f51f60fa7fc589ef2f75625fad7f024dea.tar.xz
pttbbs-162a59f51f60fa7fc589ef2f75625fad7f024dea.tar.zst
pttbbs-162a59f51f60fa7fc589ef2f75625fad7f024dea.zip
bbsmail: reindent, ignore multipart mails, apply iconv to mail subject.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1539 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs.mk2
-rw-r--r--util/Makefile9
-rw-r--r--util/bbsmail.c90
3 files changed, 47 insertions, 54 deletions
diff --git a/pttbbs.mk b/pttbbs.mk
index a00e86bf..47180ebf 100644
--- a/pttbbs.mk
+++ b/pttbbs.mk
@@ -7,7 +7,7 @@ CC?= gcc
CCACHE!= which ccache|sed -e 's/^.*\///'
PTT_CFLAGS= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include
PTT_LDFLAGS= -pipe -Wall -L/usr/local/lib
-PTT_LIBS= -lcrypt -lhz
+PTT_LIBS= -lcrypt -lhz -liconv
# enable assert()
#PTT_CFLAGS+= -DNDEBUG
diff --git a/util/Makefile b/util/Makefile
index 09f6cc32..33594270 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -20,7 +20,7 @@ CPROG_WITH_UTIL= \
openvice parse_news openticket topusr \
indexuser yearsold toplazyBM toplazyBBM \
reaper buildAnnounce inndBM shmctl \
- outmail bbsmail
+ outmail
# 下面這些程式, 會直接被 compile
CPROG_WITHOUT_UTIL= \
@@ -35,7 +35,8 @@ PROGS= ${UTIL_OBJS} ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} \
openticket.sh stock.sh topsong.sh weather.sh \
stock.perl weather.perl toplazyBM.sh toplazyBBM.sh \
dailybackup.pl tarqueue.pl waterball.pl filtermail.pl \
- getbackup.pl udnnews.pl rebuildaloha.pl railway_wrapper.pl
+ getbackup.pl udnnews.pl rebuildaloha.pl railway_wrapper.pl\
+ bbsmail
all: ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} ${PROGS}
@@ -52,6 +53,10 @@ util_${fn}.o: ../mbbsd/${fn}.c
xchatd: xchatd.c $(UTIL_OBJS) descrypt.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $@.c $(UTIL_OBJS) descrypt.c
+bbsmail: bbsmail.c ../innbbsd/str_decode.c $(UTIL_OBJS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o bbsmail -DUSE_ICONV \
+ bbsmail.c ../innbbsd/str_decode.c $(UTIL_OBJS)
+
install: $(PROGS)
install -d $(BBSHOME)/bin/
install -c -m 755 $(PROGS) $(BBSHOME)/bin/
diff --git a/util/bbsmail.c b/util/bbsmail.c
index f2390254..7e0ceb69 100644
--- a/util/bbsmail.c
+++ b/util/bbsmail.c
@@ -1,5 +1,4 @@
/* $Id$ */
-
#define _UTIL_C_
#include "bbs.h"
@@ -74,61 +73,57 @@ mailog(msg)
}
-int
-mail2bbs(userid)
- char *userid;
+int mail2bbs(char *userid)
{
- int uid;
+ int uid;
fileheader_t mymail;
char genbuf[512], title[512], sender[512], filename[512], *ip, *ptr;
time_t tmp_time;
struct stat st;
FILE *fout;
-/* check if the userid is in our bbs now */
- if (!(uid=getuser(userid)) )
- {
+
+ /* check if the userid is in our bbs now */
+ if( !(uid = getuser(userid)) ){
sprintf(genbuf, "BBS user <%s> not existed", userid);
puts(genbuf);
mailog(genbuf);
return -1;//EX_NOUSER;
}
- if(xuser.userlevel&PERM_NOOUTMAIL)
- return -1;
+ if( xuser.userlevel & PERM_NOOUTMAIL )
+ return -1; //不接受站外信
sprintf(filename, BBSHOME "/home/%c/%s", userid[0], userid);
- if (stat(filename, &st) == -1)
- {
- if (mkdir(filename, 0755) == -1)
- {
+ if( stat(filename, &st) == -1 ){
+ if( mkdir(filename, 0755) == -1 ){
printf("mail box create error %s \n", filename);
return -1;
}
}
- else if (!(st.st_mode & S_IFDIR))
- {
+ else if( !(st.st_mode & S_IFDIR) ){
printf("mail box error\n");
return -1;
}
- // printf("dir: %s\n", filename);
-
-/* allocate a file for the new mail */
-
- stampfile(filename, &mymail);
- // printf("file: %s\n", filename);
-
-/* copy the stdin to the specified file */
-
/* parse header */
-
- while (fgets(genbuf, 255, stdin))
- {
- if (!strncmp(genbuf, "From", 4))
- {
- if ((ip = strchr(genbuf, '<')) && (ptr = strrchr(ip, '>')))
- {
+ while( fgets(genbuf, sizeof(genbuf), stdin) ){
+ if( genbuf[0] == '\n' )
+ break;
+ if( strncmp(genbuf, "Subject: ", 9) == 0 ){
+ strlcpy(title, genbuf + 9, sizeof(title));
+#ifdef USE_ICONV
+ void str_decode_M3(unsigned char *str);
+ str_decode_M3(title);
+#endif
+ continue;
+ }
+ if( strncmp(genbuf, "Content-Type:", 13) == 0 ){
+ if( strstr(genbuf, "multipart") && !strstr(genbuf, "report") )
+ return -1;
+ }
+ if( strncmp(genbuf, "From", 4) == 0 ){
+ if( (ip = strchr(genbuf, '<')) && (ptr = strrchr(ip, '>')) ){
*ptr = '\0';
if (ip[-1] == ' ')
ip[-1] = '\0';
@@ -140,36 +135,27 @@ mail2bbs(userid)
ptr = "unknown";
sprintf(sender, "%s (%s)", ip + 1, ptr);
}
- else
- {
+ else{
strtok(genbuf, " \t\n\r");
- ptr= strtok(NULL, " \t\n\r");
+ ptr = strtok(NULL, " \t\n\r");
if(ptr)
strlcpy(sender, ptr, sizeof(sender));
}
continue;
}
- if (!strncmp(genbuf, "Subject: ", 9))
- {
- strlcpy(title, genbuf + 9, sizeof(title));
- continue;
- }
- if (genbuf[0] == '\n')
- break;
}
- if ((ptr = strchr(sender, '\n')))
+ if( (ptr = strchr(sender, '\n')) )
*ptr = '\0';
- if ((ptr = strchr(title, '\n')))
+ if( (ptr = strchr(title, '\n')) )
*ptr = '\0';
- if (strchr(sender, '@') == NULL) /* 由 local host 寄信 */
- {
+ if( strchr(sender, '@') == NULL ) /* 由 local host 寄信 */
strcat(sender, "@" MYHOSTNAME);
- }
- time(&tmp_time);
+/* allocate a file for the new mail */
+ stampfile(filename, &mymail);
#ifdef HMM_USE_ANTI_SPAM
for (n = 0; notitle[n]; n++)
@@ -199,9 +185,11 @@ mail2bbs(userid)
if (!title[0])
sprintf(title, "來自 %.64s", sender);
title[TTLEN] = 0;
+ time(&tmp_time);
fprintf(fout, "作者: %s\n標題: %s\n時間: %s\n",
sender, title, ctime(&tmp_time));
+/* copy the stdin to the specified file */
while (fgets(genbuf, 255, stdin))
{
#ifdef HMM_USE_ANTI_SPAM
@@ -259,10 +247,10 @@ main(int argc, char* argv[])
strlcpy(receiver, argv[1], sizeof(receiver));
strtok(receiver,".");
- if (mail2bbs(receiver))
- {
+ if (mail2bbs(receiver)){
/* eat mail queue */
- while (fgets(receiver, sizeof(receiver), stdin)) ;
+ while (fgets(receiver, sizeof(receiver), stdin))
+ ;
}
return 0;
}