From a87ab519a744439ff1ffd3627d83ed9ee3e7252a Mon Sep 17 00:00:00 2001
From: piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>
Date: Wed, 7 May 2008 14:44:00 +0000
Subject: - (internal) code refine: separate inner_send API

git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4276 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 mbbsd/edit.c |  9 ++++--
 mbbsd/mail.c | 94 +++++++++++++++++++++++++++++++++++++-----------------------
 2 files changed, 64 insertions(+), 39 deletions(-)

(limited to 'mbbsd')

diff --git a/mbbsd/edit.c b/mbbsd/edit.c
index 495b4381..965c9dbd 100644
--- a/mbbsd/edit.c
+++ b/mbbsd/edit.c
@@ -1739,9 +1739,12 @@ write_file(const char *fpath, int saveheader, int *islocal, char *mytitle, int u
     case 's':
 	if (!HasUserPerm(PERM_LOGINOK)) {
 	    local_article = 1;
-	    move(2, 0);
-	    outs("�z�|���q�L�����T�{�A�u�� Local Save�C\n");
-	    pressanykey();
+	    // only report if local can be set.
+	    if (islocal)
+	    {
+		mvouts(2, 0, "�z�|���q�L�����T�{�A�u�� Local Save�C\n");
+		pressanykey();
+	    }
 	} else
 	    local_article = 0;
 	break;
diff --git a/mbbsd/mail.c b/mbbsd/mail.c
index 29340dbc..c23298c3 100644
--- a/mbbsd/mail.c
+++ b/mbbsd/mail.c
@@ -384,15 +384,58 @@ hold_mail(const char *fpath, const char *receiver)
 	do_hold_mail(fpath, receiver, cuser.userid);
 }
 
+int
+do_innersend(const char *userid, char *mfpath, const char *title)
+{
+    fileheader_t    mhdr;
+    char            fpath[PATHLEN];
+    char	    _mfpath[PATHLEN];
+    int		    i = 0;
+    int		    oldstat = currstat;
+
+    if (!mfpath)
+	mfpath = _mfpath;
+
+    setutmpmode(SMAIL);
+
+    sethomepath(mfpath, userid);
+    stampfile(mfpath, &mhdr);
+    strlcpy(mhdr.owner, cuser.userid, sizeof(mhdr.owner));
+    strlcpy(save_title, title, sizeof(save_title));
+
+    if (vedit(mfpath, YEA, NULL) == -1) {
+	unlink(mfpath);
+	setutmpmode(oldstat);
+	return -2;
+    }
+
+    strlcpy(mhdr.title, save_title, sizeof(mhdr.title));
+    sethomefile(fpath, userid, FN_OVERRIDES);
+    i = belong(fpath, cuser.userid);
+    sethomefile(fpath, userid, FN_REJECT);
+
+    if (i || !belong(fpath, cuser.userid)) {/* Ptt: ��belong���I�Q�� */
+	sethomedir(fpath, userid);
+	if (append_record_forward(fpath, &mhdr, sizeof(mhdr), userid) == -1)
+	{
+	    unlink(mfpath);
+	    setutmpmode(oldstat);
+	    return -1;
+	}
+	sendalert(userid, ALERT_NEW_MAIL);
+    }
+    setutmpmode(oldstat);
+    return 0;
+}
+
 int
 do_send(const char *userid, const char *title)
 {
     fileheader_t    mhdr;
     char            fpath[STRLEN];
-    char            receiver[IDLEN + 1];
-    char            genbuf[PATHLEN];
-    int             internet_mail, i;
+    int             internet_mail;
     userec_t        xuser;
+    int ret	    = -1;
 
     STATINC(STAT_DOSEND);
     if (strchr(userid, '@'))
@@ -415,13 +458,9 @@ do_send(const char *userid, const char *title)
 	strlcpy(save_title, tmp_title, sizeof(save_title));
     }
 
-    setutmpmode(SMAIL);
-
-    fpath[0] = '\0';
-
     if (internet_mail) {
-	int             res, ch;
 
+	setutmpmode(SMAIL);
 	sethomepath(fpath, cuser.userid);
 	stampfile(fpath, &mhdr);
 
@@ -433,46 +472,29 @@ do_send(const char *userid, const char *title)
 	clear();
 	prints("�H��Y�N�H�� %s\n���D���G%s\n�T�w�n�H�X��? (Y/N) [Y]",
 	       userid, save_title);
-	ch = igetch();
-	switch (ch) {
+	switch (igetch()) {
 	case 'N':
 	case 'n':
 	    outs("N\n�H��w����");
-	    res = -2;
+	    ret = -2;
 	    break;
 	default:
 	    outs("Y\n�еy��, �H��ǻ���...\n");
-	    res = bsmtp(fpath, save_title, userid, NULL);
+	    ret = bsmtp(fpath, save_title, userid, NULL);
 	    hold_mail(fpath, userid);
+	    break;
 	}
 	unlink(fpath);
-	return res;
+
     } else {
-	strlcpy(receiver, userid, sizeof(receiver));
-	sethomepath(genbuf, userid);
-	stampfile(genbuf, &mhdr);
-	strlcpy(mhdr.owner, cuser.userid, sizeof(mhdr.owner));
-	if (vedit(genbuf, YEA, NULL) == -1) {
-	    unlink(genbuf);
-	    clear();
-	    return -2;
-	}
-	/* why not make title here? */
-	strlcpy(mhdr.title, save_title, sizeof(mhdr.title));
-	clear();
-	sethomefile(fpath, userid, FN_OVERRIDES);
-	i = belong(fpath, cuser.userid);
-	sethomefile(fpath, userid, FN_REJECT);
 
-	if (i || !belong(fpath, cuser.userid)) {/* Ptt: ��belong���I�Q�� */
-	    sethomedir(fpath, userid);
-	    if (append_record_forward(fpath, &mhdr, sizeof(mhdr), userid) == -1)
-		return -1;
-	    sendalert(userid,ALERT_NEW_MAIL);
-	}
-	hold_mail(genbuf, userid);
-	return 0;
+	ret = do_innersend(userid, fpath, save_title);
+	if (ret == 0) // success
+	    hold_mail(fpath, userid);
+
+	clear();
     }
+    return ret;
 }
 
 void
-- 
cgit v1.2.3