phpbbs.mail.c
来自「linux/unix环境下的建站系统」· C语言 代码 · 共 839 行 · 第 1/2 页
C
839 行
#include "php_kbs_bbs.h" PHP_FUNCTION(bbs_checknewmail){ char *userid; int userid_len; char qry_mail_dir[STRLEN]; if (zend_parse_parameters(1 TSRMLS_CC, "s", &userid, &userid_len) != SUCCESS) { WRONG_PARAM_COUNT; } if( userid_len > IDLEN ) userid[IDLEN]=0; setmailfile(qry_mail_dir, userid, DOT_DIR); RETURN_LONG( check_query_mail(qry_mail_dir, NULL) );}PHP_FUNCTION(bbs_mail_get_num){ char *userid; int userid_len, total, newmail; char qry_mail_dir[STRLEN]; if (zend_parse_parameters(1 TSRMLS_CC, "s", &userid, &userid_len) != SUCCESS) { WRONG_PARAM_COUNT; } if( userid_len > IDLEN ) userid[IDLEN]=0; setmailfile(qry_mail_dir, userid, DOT_DIR); newmail = check_query_mail(qry_mail_dir, &total); if (array_init(return_value) == FAILURE) { RETURN_FALSE; } add_assoc_long(return_value, "total", total); add_assoc_bool(return_value, "newmail", newmail);}/** * get the number of one user's mail. * prototype: * bool bbs_getmailnum(string userid,long &total,long &unread); * * @return TRUE on success, * FALSE on failure. * and return total and unread in argument * @author KCN */PHP_FUNCTION(bbs_getmailnum){ zval *total, *unread; char *userid; int userid_len; struct fileheader x; char path[80]; int totalcount = 0, unreadcount = 0; int ac = ZEND_NUM_ARGS(); int fd; long oldtotal,oldunread; if (ac != 5 || zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC, "szzll", &userid, &userid_len, &total, &unread, &oldtotal, &oldunread) == FAILURE) { WRONG_PARAM_COUNT; } if (userid_len > IDLEN) WRONG_PARAM_COUNT; /* * check for parameter being passed by reference */ if (!PZVAL_IS_REF(total) || !PZVAL_IS_REF(unread)) { zend_error(E_WARNING, "Parameter wasn't passed by reference"); RETURN_FALSE; } if( !strcmp(userid, getCurrentUser()->userid) && oldtotal && getSession()->currentuinfo && !(getSession()->currentuinfo->mailcheck & CHECK_MAIL) ){ totalcount = oldtotal; unreadcount = oldunread; ZVAL_LONG(total, totalcount); ZVAL_LONG(unread, unreadcount); RETURN_TRUE; } setmailfile(path, userid, DOT_DIR); fd = open(path, O_RDONLY); if (fd == -1) RETURN_FALSE; while (read(fd, &x, sizeof(x)) > 0) { totalcount++; if (!(x.accessed[0] & FILE_READ)) unreadcount++; } close(fd); /* * make changes to the parameter */ ZVAL_LONG(total, totalcount); ZVAL_LONG(unread, unreadcount); if( getSession()->currentuinfo ) getSession()->currentuinfo->mailcheck |= CHECK_MAIL; RETURN_TRUE;}/** * get the number of one user's mail path. * prototype: * int bbs_getmailnum2(string path); * * @return the number * @author binxun */PHP_FUNCTION(bbs_getmailnum2){ char *path; int path_len; int ac = ZEND_NUM_ARGS(); if (ac != 1 || zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC, "s", &path, &path_len) == FAILURE) { WRONG_PARAM_COUNT; } RETURN_LONG(getmailnum(path));}/** * Fetch a list of mails in one user's mail path file into an array. * prototype: * array bbs_getmails(char *filename,int start,int num); * * start - 0 based * @return array of loaded mails on success, * -1 no mail * FALSE on failure. * @author binxun */PHP_FUNCTION(bbs_getmails){ char *mailpath; int mailpath_len; int total, rows, i; long start,num; struct fileheader *mails; zval *element; char flags[2]; /* flags[0]: status * flags[1]: reply status */ int ac = ZEND_NUM_ARGS(); /* * getting arguments */ if (ac != 3 || zend_parse_parameters(3 TSRMLS_CC, "sll", &mailpath, &mailpath_len,&start,&num) == FAILURE) { WRONG_PARAM_COUNT; } total = getmailnum(mailpath); if (!total) RETURN_LONG(-1); if (array_init(return_value) == FAILURE) { RETURN_FALSE; } if(start >= total)RETURN_FALSE; if(start + num > total)num = total - start; mails = emalloc(num * sizeof(struct fileheader)); if (!mails) RETURN_FALSE; rows = get_records(mailpath, mails, sizeof(struct fileheader), start+1, num);//it is 1 -based if (rows == -1) RETURN_FALSE; for (i = 0; i < rows; i++) { MAKE_STD_ZVAL(element); array_init(element); if (mails[i].accessed[0] & FILE_READ) { if (mails[i].accessed[0] & FILE_MARKED) flags[0] = 'm'; else flags[0] = ' '; } else { if (mails[i].accessed[0] & FILE_MARKED) flags[0] = 'M'; else flags[0] = 'N'; } if (mails[i].accessed[0] & FILE_REPLIED) { if (mails[i].accessed[0] & FILE_FORWARDED) flags[1] = 'A'; else flags[1] = 'R'; } else { if (mails[i].accessed[0] & FILE_FORWARDED) flags[1] = 'F'; else flags[1] = ' '; } bbs_make_article_array(element, mails + i, flags, sizeof(flags)); zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *) &element, sizeof(zval *), NULL); } efree(mails); if( getSession()->currentuinfo ) getSession()->currentuinfo->mailcheck &= ~CHECK_MAIL;}/** * Get mail used space * @author stiger */PHP_FUNCTION(bbs_getmailusedspace){ RETURN_LONG(get_mailusedspace(getCurrentUser(),1)/1024);}/** * Whether save to sent box * @author atppp */PHP_FUNCTION(bbs_is_save2sent){ RETURN_LONG(HAS_MAILBOX_PROP(getSession()->currentuinfo, MBP_SAVESENTMAIL));}/* * bbs_can_send_mail () * @author stiger */PHP_FUNCTION(bbs_can_send_mail){ long is_reply = 0; int ret; int ac = ZEND_NUM_ARGS(); if (ac == 1) { if (zend_parse_parameters(1 TSRMLS_CC, "l", &is_reply) == FAILURE) { WRONG_PARAM_COUNT; } } else { if (ac != 0) { WRONG_PARAM_COUNT; } } ret = check_mail_perm(getCurrentUser(), NULL); if (ret > 0) { if (is_reply) { RETURN_LONG(ret == 6 ? 1 : 0); } else { RETURN_LONG(0); } } else { RETURN_LONG(1); }}/** * load mail list. user custom mailboxs. * prototype: * array bbs_loadmaillist(char *userid); * * @return array of loaded mails on success, * -1 no mailbox * FALSE on failure. * @author binxun */PHP_FUNCTION(bbs_loadmaillist){ char *userid; int userid_len; char buf[10]; struct _mail_list maillist; struct userec *user; int i; zval *element; int ac = ZEND_NUM_ARGS(); /* * getting arguments */ if (ac != 1 || zend_parse_parameters(1 TSRMLS_CC, "s", &userid, &userid_len) == FAILURE) { WRONG_PARAM_COUNT; } if (userid_len > IDLEN) RETURN_FALSE; if (!getuser(userid, &user)) RETURN_FALSE; load_mail_list(user, &maillist); if (maillist.mail_list_t < 0 || maillist.mail_list_t > MAILBOARDNUM) //no custom mail box { RETURN_FALSE; } if (!maillist.mail_list_t) RETURN_LONG(-1); if (array_init(return_value) == FAILURE) { RETURN_FALSE; } for (i = 0; i < maillist.mail_list_t; i++) { MAKE_STD_ZVAL(element); array_init(element); sprintf(buf, ".%s", maillist.mail_list[i] + 30); //assign_maillist(element,maillist.mail_list[i],buf); add_assoc_string(element, "boxname", maillist.mail_list[i], 1); add_assoc_string(element, "pathname", buf, 1); zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *) &element, sizeof(zval *), NULL); }}/** * change mail list and save new for user custom mailboxs. * prototype: * int bbs_changemaillist(bool bAdd,char* userid,char* newboxname,int index); index--0 based * * @return * 0 ---- fail * -1 ---- success * >0 --- reach to max number! * @author binxun */PHP_FUNCTION(bbs_changemaillist){ char *boxname; int boxname_len; char *userid; int userid_len; zend_bool bAdd; long index; struct _mail_list maillist; char buf[10], path[PATHLEN]; struct userec *user; int i; struct stat st; int ac = ZEND_NUM_ARGS(); /* * getting arguments */ if (ac != 4 || zend_parse_parameters(4 TSRMLS_CC, "bssl", &bAdd, &userid, &userid_len, &boxname, &boxname_len, &index) == FAILURE) { WRONG_PARAM_COUNT; } if (userid_len > IDLEN) RETURN_LONG(0); if (boxname_len > 29) boxname[29] = '\0'; if (!getuser(userid, &user)) RETURN_LONG(0); load_mail_list(user, &maillist); if (maillist.mail_list_t < 0 || maillist.mail_list_t > MAILBOARDNUM) //no custom mail box { RETURN_LONG(0); } if (bAdd) //add { if (maillist.mail_list_t == MAILBOARDNUM) RETURN_LONG(MAILBOARDNUM); //最大值了 i = 0; while (1) //search for new mailbox path name { i++; sprintf(buf, ".MAILBOX%d", i); setmailfile(path, getCurrentUser()->userid, buf); if (stat(path, &st) == -1) break; } f_touch(path); sprintf(buf, "MAILBOX%d", i); strcpy(maillist.mail_list[maillist.mail_list_t], boxname); strcpy(maillist.mail_list[maillist.mail_list_t] + 30, buf); maillist.mail_list_t += 1; save_mail_list(&maillist, getSession()); } else //delete { if (index < 0 || index > maillist.mail_list_t - 1) RETURN_LONG(-1); sprintf(buf, ".%s", maillist.mail_list[index] + 30); setmailfile(path, getCurrentUser()->userid, buf); if (get_num_records(path, sizeof(struct fileheader)) != 0) RETURN_LONG(0); f_rm(path); for (i = index; i < maillist.mail_list_t - 1; i++) memcpy(maillist.mail_list[i], maillist.mail_list[i + 1], sizeof(maillist.mail_list[i])); maillist.mail_list_t--; save_mail_list(&maillist, getSession()); } if( getSession()->currentuinfo ) getSession()->currentuinfo->mailcheck &= ~CHECK_MAIL; RETURN_LONG(-1);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?