⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lymail.c

📁 基于rtos开发的浏览器!
💻 C
📖 第 1 页 / 共 3 页
字号:
#include "HTUtils.h"#include "tcp.h"#include "HTParse.h"#include "LYGlobalDefs.h"#include "HTAlert.h"#include "LYCurses.h"#include "LYSignal.h"#include "LYUtils.h"#include "LYClean.h"#include "LYStrings.h"#include "GridText.h"#include "LYSystem.h"#include "LYMail.h"#include "LYCharSets.h"  /* to get current charset for mail header */#include "LYLeaks.h"#define FREE(x) if (x) {free(x); x = NULL;}BOOLEAN term_letter;	/* Global variable for async i/o. */PRIVATE void terminate_letter  PARAMS((int sig));PRIVATE void remove_tildes PARAMS((char *string));/***  mailform() sends form content to the mailto address(es). - FM*/PUBLIC void mailform ARGS4(	char *, 	mailto_address,	char *, 	mailto_subject,	char *, 	mailto_content,	char *, 	mailto_type){    FILE *fd;    char *address = NULL;    char *ccaddr = NULL;    char *keywords = NULL;    char *searchpart = NULL;    char *cp = NULL, *cp0 = NULL, *cp1 = NULL;    char subject[80];    char self[80];    char cmd[512];    int len, i, ch;#if defined(VMS) || defined(DOSPATH)    char my_tmpfile[256];    char *address_ptr1, *address_ptr2;    char *command = NULL;    BOOLEAN first = TRUE;    BOOLEAN isPMDF = FALSE;    char hdrfile[256];    FILE *hfd;    if (!strncasecomp(system_mail, "PMDF SEND", 9)) {	isPMDF = TRUE;    }#endif /* VMS */    if (!mailto_address || !mailto_content) {	HTAlert(BAD_FORM_MAILTO);	return;    }    subject[0] = '\0';    self[0] = '\0';    if ((cp = (char *)strchr(mailto_address,'\n')) != NULL)	*cp = '\0';    StrAllocCopy(address, mailto_address);    /*     *	Check for a ?searchpart. - FM     */    if ((cp = strchr(address, '?')) != NULL) {	StrAllocCopy(searchpart, cp);	*cp = '\0';	cp = (searchpart + 1);	if (*cp != '\0') {	    /*	     *	Seek and handle a subject=foo. - FM	     */	    while (*cp != '\0') {		if ((*(cp - 1) == '?' || *(cp - 1) == '&') &&		    !strncasecomp(cp, "subject=", 8))		    break;		cp++;	    }	    if (*cp) {		cp += 8;		if ((cp1 = strchr(cp, '&')) != NULL) {		    *cp1 = '\0';		}		if (*cp) {		    HTUnEscape(subject);		    LYstrncpy(subject, cp, 70);		}		if (cp1) {		    *cp1 = '&';		    cp1 = NULL;		}	    }	    /*	     *	Seek and handle to=address(es) fields.	     *	Appends to address. - FM	     */	    cp = (searchpart + 1);	    while (*cp != '\0') {		if ((*(cp - 1) == '?' || *(cp - 1) == '&') &&		    !strncasecomp(cp, "to=", 3)) {		    cp += 3;		    if ((cp1 = strchr(cp, '&')) != NULL) {			*cp1 = '\0';		    }		    while (*cp == ',' || isspace((unsigned char)*cp))			cp++;		    if (*cp) {			if (*address) {			    StrAllocCat(address, ",");			}			StrAllocCat(address, cp);		    }		    if (cp1) {			*cp1 = '&';			cp = cp1;			cp1 = NULL;		    } else {			break;		    }		}		cp++;	    }	    /*	     *	Seek and handle cc=address(es) fields.	Excludes	     *	Bcc=address(es) as unsafe.  We may append our own	     *	cc (below) as a list for the actual mailing. - FM	     */	    cp = (searchpart + 1);	    while (*cp != '\0') {		if ((*(cp - 1) == '?' || *(cp - 1) == '&') &&		    !strncasecomp(cp, "cc=", 3)) {		    cp += 3;		    if ((cp1 = strchr(cp, '&')) != NULL) {			*cp1 = '\0';		    }		    while (*cp == ',' || isspace((unsigned char)*cp))			cp++;		    if (*cp) {			if (ccaddr == NULL) {			    StrAllocCopy(ccaddr, cp);			} else {			    StrAllocCat(ccaddr, ",");			    StrAllocCat(ccaddr, cp);			}		    }		    if (cp1) {			*cp1 = '&';			cp = cp1;			cp1 = NULL;		    } else {			break;		    }		}		cp++;	    }	    /*	     *	Seek and handle keywords=term(s) fields. - FM	     */	    cp = (searchpart + 1);	    while (*cp != '\0') {		if ((*(cp - 1) == '?' || *(cp - 1) == '&') &&		    !strncasecomp(cp, "keywords=", 9)) {		    cp += 9;		    if ((cp1 = strchr(cp, '&')) != NULL) {			*cp1 = '\0';		    }		    while (*cp == ',' || isspace((unsigned char)*cp))			cp++;		    if (*cp) {			if (keywords == NULL) {			    StrAllocCopy(keywords, cp);			} else {			    StrAllocCat(keywords, cp);			    StrAllocCat(keywords, ", ");			}		    }		    if (cp1) {			*cp1 = '&';			cp = cp1;			cp1 = NULL;		    } else {			break;		    }		}		cp++;	    }	    if (keywords != NULL) {		if (*keywords != '\0') {		    HTUnEscape(keywords);		} else {		    FREE(keywords);		}	    }	    FREE(searchpart);	}    }    /*     * Convert any Explorer semi-colon Internet address     * separators to commas. - FM     */    cp = address;    while ((cp1 = strchr(cp, '@')) != NULL) {	cp1++;	if ((cp0 = strchr(cp1, ';')) != NULL) {	    *cp0 = ',';	    cp1 = cp0 + 1;	}	cp = cp1;    }    if (address[(strlen(address) - 1)] == ',')	address[(strlen(address) - 1)] = '\0';    if (*address == '\0') {	FREE(address);	FREE(ccaddr);	FREE(keywords);	HTAlert(BAD_FORM_MAILTO);	return;    }    if (ccaddr != NULL) {	cp = ccaddr;	while ((cp1 = strchr(cp, '@')) != NULL) {	    cp1++;	    if ((cp0 = strchr(cp1, ';')) != NULL) {		*cp0 = ',';		cp1 = cp0 + 1;	    }	    cp = cp1;	}	if (ccaddr[(strlen(ccaddr) - 1)] == ',') {	    ccaddr[(strlen(ccaddr) - 1)] = '\0';	}	if (*ccaddr == '\0') {	    FREE(ccaddr);	}    }    /*     *	Unescape the address and ccaddr fields. - FM     */    HTUnEscape(address);    if (ccaddr != NULL) {	HTUnEscape(ccaddr);    }    /*     *	Allow user to edit the default Subject - FM     */    if (subject[0] == '\0') {	if (mailto_subject && *mailto_subject) {	    LYstrncpy(subject, mailto_subject, 70);	} else {	    strcpy(subject, "mailto:");	    LYstrncpy((char*)&subject[7], address, 63);	}    }    _statusline(SUBJECT_PROMPT);    if ((ch = LYgetstr(subject, VISIBLE, 71, NORECALL)) < 0) {	/*	 * User cancelled via ^G. - FM	 */	_statusline(FORM_MAILTO_CANCELLED);	sleep(InfoSecs);	FREE(address);	FREE(ccaddr);	FREE(keywords);	return;    }    /*     *	Allow user to specify a self copy via a CC:     *	entry, if permitted. - FM     */    if (!LYNoCc) {	sprintf(self, "%.79s", (personal_mail_address ?				personal_mail_address : ""));	self[79] = '\0';	_statusline("Cc: ");	if ((ch = LYgetstr(self, VISIBLE, sizeof(self), NORECALL)) < 0) {	    /*	     * User cancelled via ^G. - FM	     */	    _statusline(FORM_MAILTO_CANCELLED);	    sleep(InfoSecs);	    FREE(address);	    FREE(ccaddr);	    FREE(keywords);	    return;	}	remove_tildes(self);	if (ccaddr == NULL) {	    StrAllocCopy(ccaddr, self);	} else {	    StrAllocCat(ccaddr, ",");	    StrAllocCat(ccaddr, self);	}    }#if defined(VMS) || defined(DOSPATH)    tempname(my_tmpfile, NEW_FILE);    if (((cp = strrchr(my_tmpfile, '.')) != NULL) &&	NULL == strchr(cp, ']') &&	NULL == strchr(cp, '/')) {	*cp = '\0';	strcat(my_tmpfile, ".txt");    }    if ((fd = LYNewTxtFile(my_tmpfile)) == NULL) {	HTAlert(FORM_MAILTO_FAILED);	FREE(address);	FREE(ccaddr);	FREE(keywords);	return;    }    if (isPMDF) {	tempname(hdrfile, NEW_FILE);	if (((cp = strrchr(hdrfile, '.')) != NULL) &&	    NULL == strchr(cp, ']') &&	    NULL == strchr(cp, '/')) {	    *cp = '\0';	    strcat(hdrfile, ".txt");	}	if ((hfd = LYNewTxtFile(hdrfile)) == NULL) {	    HTAlert(FORM_MAILTO_FAILED);	    FREE(address);	    FREE(ccaddr);	    FREE(keywords);	    return;	}    }#ifdef VMS    if (isPMDF) {	if (mailto_type && *mailto_type) {	    fprintf(hfd, "Mime-Version: 1.0\n");	    fprintf(hfd, "Content-Type: %s\n", mailto_type);	    if (personal_mail_address && *personal_mail_address)		fprintf(hfd, "From: %s\n", personal_mail_address);	    }    } else if (mailto_type &&	       !strncasecomp(mailto_type, "multipart/form-data", 19)) {	/*	 *  Ugh!  There's no good way to include headers while	 *  we're still using "generic" VMS MAIL, so we'll put	 *  this in the body of the message. - FM	 */	fprintf(fd, "X-Content-Type: %s\n\n", mailto_type);    }#else    if (mailto_type && *mailto_type) {	fprintf(fd, "Mime-Version: 1.0\n");	fprintf(fd, "Content-Type: %s\n", mailto_type);    }    fprintf(fd,"To: %s\n", address);    if (personal_mail_address && *personal_mail_address)	fprintf(fd,"From: %s\n", personal_mail_address);    remove_tildes(self);    fprintf(fd,"Subject: %.70s\n\n", subject);#endif#else    sprintf(cmd, "%s %s", system_mail, system_mail_flags);    if ((fd = popen(cmd, "w")) == NULL) {	HTAlert(FORM_MAILTO_FAILED);	FREE(address);	FREE(ccaddr);	FREE(keywords);	return;    }    if (mailto_type && *mailto_type) {	fprintf(fd, "Mime-Version: 1.0\n");	fprintf(fd, "Content-Type: %s\n", mailto_type);    }    fprintf(fd, "To: %s\n", address);    if (personal_mail_address && *personal_mail_address)	fprintf(fd, "From: %s\n", personal_mail_address);    if (ccaddr != NULL && *ccaddr != '\0')	fprintf(fd, "Cc: %s\n", ccaddr);    fprintf(fd, "Subject: %s\n\n", subject);    if (keywords != NULL && *keywords != '\0')	fprintf(fd, "Keywords: %s\n", keywords);    _statusline(SENDING_FORM_CONTENT);#endif /* VMS */    /*     *	Break up the content into lines with a maximum length of 78.     *	If the ENCTYPE was text/plain, we have physical newlines and     *	should take them into account.	Otherwise, the actual newline     *	characters in the content are hex escaped. - FM     */    while((cp = strchr(mailto_content, '\n')) != NULL) {	*cp = '\0';	i = 0;	len = strlen(mailto_content);	while (len > 78) {	    strncpy(cmd, (char *)&mailto_content[i], 78);	    cmd[78] = '\0';	    fprintf(fd, "%s\n", cmd);	    i += 78;	    len = strlen((char *)&mailto_content[i]);	}	fprintf(fd, "%s\n", (char *)&mailto_content[i]);	mailto_content = (cp+1);    }    i = 0;    len = strlen(mailto_content);    while (len > 78) {	strncpy(cmd, (char *)&mailto_content[i], 78);	cmd[78] = '\0';	fprintf(fd, "%s\n", cmd);	i += 78;	len = strlen((char *)&mailto_content[i]);    }    if (len)	fprintf(fd, "%s\n", (char *)&mailto_content[i]);#ifdef UNIX    pclose(fd);    sleep(MessageSecs);#endif /* UNIX */#if defined(VMS) || defined(DOSPATH)    fclose(fd);#ifdef VMS    /*     *	Set the mail command. - FM     */    if (isPMDF) {	/*	 *  For PMDF, put any keywords and the subject	 *  in the header file and close it. - FM	 */	if (keywords != NULL && *keywords != '\0') {	    fprintf(hfd, "Keywords: %s\n", keywords);	}	fprintf(hfd, "Subject: %s\n\n", subject);	fclose(hfd);	/*	 *  Now set up the command. - FM	 */	sprintf(cmd,		"%s %s %s,%s ",		system_mail,		system_mail_flags,		hdrfile,		my_tmpfile);    } else {	/*	 *  For "generic" VMS MAIL, include the subject in the	 *  command, and ignore any keywords to minimize risk	 *  of them making the line too long or having problem	 *  characters. - FM	 */	sprintf(cmd,		"%s %s%s/subject=\"%s\" %s ",		system_mail,		system_mail_flags,		(strncasecomp(system_mail, "MAIL", 4) ? "" : "/noself"),		subject,		my_tmpfile);    }    StrAllocCopy(command, cmd);    /*     *	Now add all the people in the address field. - FM     */    address_ptr1 = address;    do {	if ((cp = strchr(address_ptr1, ',')) != NULL) {	    address_ptr2 = (cp+1);	    *cp = '\0';	} else {	    address_ptr2 = NULL;	}	/*	 *  4 letters is arbitrarily the smallest possible mail	 *  address, at least for lynx.  That way extra spaces	 *  won't confuse the mailer and give a blank address.	 */	if (strlen(address_ptr1) > 3) {	    if (!first) {		StrAllocCat(command, ",");	    }	    sprintf(cmd, mail_adrs, address_ptr1);	    StrAllocCat(command, cmd);	    first = FALSE;	}	address_ptr1 = address_ptr2;    } while (address_ptr1 != NULL);    /*     *	Now add all the people in the CC field. - FM     */    if (ccaddr != NULL && *ccaddr != '\0') {	address_ptr1 = ccaddr;	do {	    if ((cp = strchr(address_ptr1, ',')) != NULL) {		address_ptr2 = (cp+1);		*cp = '\0';	    } else {		address_ptr2 = NULL;	    }	    /*	     *	4 letters is arbitrarily the smallest possible mail	     *	address, at least for lynx.  That way extra spaces	     *	won't confuse the mailer and give a blank address.	     */	    if (strlen(address_ptr1) > 3) {		StrAllocCat(command, ",");		sprintf(cmd, mail_adrs, address_ptr1);		if (isPMDF) {		    strcat(cmd, "/CC");		}		StrAllocCat(command, cmd);	    }	    address_ptr1 = address_ptr2;	} while (address_ptr1 != NULL);    }    stop_curses();    printf("Sending form content:\n\n$ %s\n\nPlease wait...", command);    system(command);    FREE(command);    sleep(AlertSecs);    start_curses();    remove(my_tmpfile);    remove(hdrfile);#else /* DOSPATH */    sprintf(cmd, "%s -t \"%s\" -F %s", system_mail, address, my_tmpfile);    stop_curses();    printf("Sending form content:\n\n$ %s\n\nPlease wait...", cmd);    system(cmd);    sleep(MessageSecs);    start_curses();    remove(my_tmpfile);#endif#endif /* VMS */    FREE(address);    FREE(ccaddr);    FREE(keywords);    return;}/***  mailmsg() sends a message to the owner of the file, if one is defined,**  telling of errors (i.e., link not available).*/PUBLIC void mailmsg ARGS4(	int,		cur,	char *, 	owner_address,	char *, 	filename,	char *, 	linkname){    FILE *fd, *fp;    char *address = NULL;    char *searchpart = NULL;    char cmd[512], *cp, *cp0, *cp1;#if defined(VMS) || defined(DOSPATH)    char my_tmpfile[256];    char *address_ptr1, *address_ptr2;    char *command = NULL;    BOOLEAN first = TRUE;    BOOLEAN isPMDF = FALSE;    char hdrfile[256];    FILE *hfd;    if (!strncasecomp(system_mail, "PMDF SEND", 9)) {	isPMDF = TRUE;    }#endif /* VMS */    if (owner_address == NULL || *owner_address == '\0') {	return;    }    if ((cp = (char *)strchr(owner_address,'\n')) != NULL)	*cp = '\0';    StrAllocCopy(address, owner_address);    /*     *	Check for a ?searchpart. - FM     */    if ((cp = strchr(address, '?')) != NULL) {	StrAllocCopy(searchpart, cp);	*cp = '\0';	cp = (searchpart + 1);	if (*cp != '\0') {	    /*	     *	Seek and handle to=address(es) fields.	     *	Appends to address.  We ignore any other	     *	headers in the ?searchpart. - FM	     */	    cp = (searchpart + 1);	    while (*cp != '\0') {		if ((*(cp - 1) == '?' || *(cp - 1) == '&') &&		    !strncasecomp(cp, "to=", 3)) {		    cp += 3;		    if ((cp1 = strchr(cp, '&')) != NULL) {			*cp1 = '\0';		    }		    while (*cp == ',' || isspace((unsigned char)*cp))			cp++;		    if (*cp) {			if (*address) {			    StrAllocCat(address, ",");			}			StrAllocCat(address, cp);		    }		    if (cp1) {			*cp1 = '&';			cp = cp1;			cp1 = NULL;		    } else {			break;		    }		}		cp++;	    }	}    }    /*     *	Convert any Explorer semi-colon Internet address     *	separators to commas. - FM     */    cp = address;    while ((cp1 = strchr(cp, '@')) != NULL) {	cp1++;	if ((cp0 = strchr(cp1, ';')) != NULL) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -