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

📄 mail.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	     ((mailrc_ptr = fopen(mailrc_str,"r")) == NULL)	   )	{  	/* 		 * .mailrc not found, so get the mail variables by 		 * sending a set command to the mail  program		 */	     	mt_mail_start_cmd("set");/*		while (mt_mail_get_line()) */		while (MT_MAIL_GET_LINE) 		{			s = &line[strlen(line) - 1];			*s-- = '\0';			if ((p = index(line, '=')) != NULL) 			{				*p++ = '\0';				if (*p == '"' && *s == '"') 				{					p++;					*s = '\0';				}				mt_assign(line, p);			} else				mt_assign(line, "");		}	}	else	{ 	/* 		 * set the mail variables by directly reading .mailrc		 */		while (fgets(line, LINE_SIZE, mailrc_ptr) != NULL) 		{			if (*line == '\n'  || *line == '\t' || *line == ' ' )				continue;	 		s = &line[strlen(line) - 1];			*s-- = '\0';				/* skip over 'set' command in .mailrc file */			tmp_line = line;			if ((line = index(line, ' ')) != NULL)				*line++;			else				line = tmp_line;			if ((p = index(line, '=')) != NULL) 			{				*p++ = '\0';				if ((*p == '"'  && *s == '"') || 				    (*p == '\'' && *s == '\'' )) 				{					p++;					*s = '\0';				}				mt_assign(line, p);			} else				mt_assign(line, "");		}	}}/* * Set (or unset) a Mail variable. */voidmt_set_var(var, val)	char           *var, *val;{	if (val == 0)		mt_mail_cmd("unset %s", var);	else if (strlen(val) == 0)		mt_mail_cmd("set %s", var);	else		mt_mail_cmd("set %s=\"%s\"", var, val);}/* * Get Mail's working directory. */voidmt_get_mailwd(dir)	char           *dir;{	mt_mail_cmd("!pwd");	mt_info[strlen(mt_info) - 1] = '\0';	(void)strcpy(dir, mt_info);}/* * Set Mail's working directory. */voidmt_set_mailwd(dir)	char           *dir;{	mt_mail_cmd("cd %s", dir);}/* * Reply to the specified message. Put reply in "file". If "all", reply to * all recipients. If "orig", include original message. Called from * mt_reply_proc  */intmt_reply_msg(msg, file, all, orig)	int             msg;	char           *file;	int             all;	int             orig;{	FILE           *replyf;	if(!(replyf = mt_fopen(file, "w")))		return(FALSE);	(void)chmod(file, 0600);	(void)mt_insert_msg(replyf, msg, all, 0, TRUE);	if (mt_value("askcc"))		(void) fprintf (replyf, "Cc: %s\n", 		mt_use_fields ? "|>other recipients<|" : "");        if (mt_value("askbcc"))                (void) fprintf (replyf, "Bcc: %s\n",                 mt_use_fields ? "|>blind carbon copies<|" : "");        (void)fprintf(replyf, "\n");        if (orig)                (void)mt_insert_msg(replyf, 0, FALSE, msg, TRUE);        if (mt_use_fields)                (void)fprintf(replyf, "|>body of message<|\n");	(void)fclose(replyf);	return(TRUE);}/* * Compose a message. * Put in Cc: blank fields if "askcc" set. * Include original message if "orig" set. * Called from mt_comp_proc */intmt_compose_msg(msg, file, askcc, orig)	int             msg;	char           *file;	int             askcc, orig;{	FILE           *replyf;	if(!(replyf = mt_fopen(file, "w")))		return(FALSE);	(void)chmod(file, 0600);	(void)fprintf(replyf, "To: %s\n",		(mt_use_fields ? "|>recipients<|" : ""));	if (mt_value("asksub"))		(void)fprintf(replyf, "Subject: %s\n",		(mt_use_fields ? "|>subject<|" : ""));	if (askcc)		(void)fprintf(replyf, "Cc: %s\n",		(mt_use_fields ? "|>other recipients<|" : ""));        if (mt_value("askbcc"))                (void) fprintf (replyf, "Bcc: %s\n",                  mt_use_fields ? "|>blind carbon copies<|" : "");        (void)fprintf(replyf, "\n");        if (mt_use_fields)                (void)fprintf(replyf, "|>body of message<|\n");        if (orig) {                (void)fprintf(replyf,                        "\n----- Begin %s Message -----\n\n",                        (mt_3x_compatibility ? "Forwarded" : "Included"));                (void)mt_insert_msg(replyf, 0, FALSE, msg, FALSE);                (void)fprintf(replyf,                        "\n----- End %s Message -----\n\n",                        (mt_3x_compatibility ? "Forwarded" : "Included"));        }	(void)fclose(replyf);	return(TRUE);}/* * Includes specified message. * Message is indented if "indent" is set. * Called from mt_include_proc.  */intmt_include_msg(msg, file, indented)	int             msg;	char           *file;	int             indented;{	FILE           *replyf;	if(!(replyf = mt_fopen(file, "w")))		return(FALSE);	(void)chmod(file, 0600);        if (!indented)                (void)fprintf(replyf,                        "\n----- Begin %s Message -----\n\n",                         (mt_3x_compatibility ? "Forwarded" : "Included"));	(void)mt_insert_msg(replyf, 0, FALSE, msg, indented);        if (!indented)                 (void)fprintf(replyf,                        "\n----- End %s Message -----\n\n",                          (mt_3x_compatibility ? "Forwarded" : "Included"));	(void)fclose(replyf);	return(TRUE);}static voidmt_insert_msg(file, replyto, replyall, include, indented)	FILE           *file;	int             replyto, replyall, include, indented;{	char           *escp;	int             newline;	if (!(escp = mt_value("escape")))		escp = "~";	if (replyto != 0)                  /* sends command Reply msg# or reply msg# to Mail */		(void) fprintf(mt_mailin, "%s %d\n",			(replyall ? "Reply" : "reply"), replyto);	else		(void) fprintf(mt_mailin, "m\n");	if (include) {                /*                 * sends command "~m" to Mail. This inserts message, indented                 * by one tab, or whatever is the user's indentprefix.                 */		(void) fprintf(mt_mailin, "%c%c %d\n\n",			*escp, (indented ? 'm' : 'f'), include);	}	(void)fprintf(mt_mailin, "%cp\n%cq\n", *escp, *escp);	/*	 * sends command ~p to Mail, which prints the contents of the message	 * buffer, thereby getting To, Subject, cc fields that Mail inserted,	 * plus the included message, if any. Then sends command ~q, which	 * cause message composition operation to be aborted. 	 */		(void)fflush(mt_mailin);	while (fgets(line, LINE_SIZE,  mt_mailout))		if (strcmp(line, "Message contains:\n") == 0)			break;	newline = 0;	while (fgets(line, LINE_SIZE, mt_mailout)) {		if (strcmp(line, "(continue)\n") == 0)			break;			/* copy lines from Mail into reply subwindow */		else if (strcmp(line, "\n") == 0) 			++ newline;	/* delay putting out blank lines					 * until see some non blank lines */		else {			while (newline > 0) {				fputs("\n", file);				newline--;			}			fputs(line, file); 		}	}	if (include)		fputs("\n", file); 	while (fgets(line, LINE_SIZE, mt_mailout))		if (strcmp(line, "Interrupt\n") == 0)			break;}/* * Reload the specified message from the specified file. */voidmt_load_msg(msg, file)	int             msg;	char           *file;{	mt_mail_cmd("load %d %s", msg, file);}/* * Save a message in a file or folder. * Return FALSE on failure, TRUE on success. */intmt_copy_msg(msg, file)	int             msg;	char           *file;{	register char  *p;	extern char    *index();	mt_mail_cmd("copy %d %s", msg, file);	/* look for '"file" [Appended]'  or '"file" [New file]' */	if ((p = index(mt_info, '[')) && ((strncmp(++p, "Appended", 8) == 0) ||					  (strncmp(p, "New file", 8) == 0)))		return (TRUE);	else		return (FALSE);}/* * Save messages in a file or folder. * Return FALSE on failure, TRUE on success. */intmt_copy_msgs(from, to, file)	int             from, to;	char           *file;{	register char  *p;	extern char    *index();	mt_mail_cmd("copy %d-%d %s", from, to, file);	/* look for '"file" [Appended]'  or '"file" [New file]' */	if ((p = index(mt_info, '[')) && ((strncmp(++p, "Appended", 8) == 0) ||					  (strncmp(p, "New file", 8) == 0)))		return (TRUE);	else		return (FALSE);}/* * Print a message. */voidmt_print_msg(msg, file, ign)	int             msg;	char           *file;	int             ign;{	if (ign) {		/*		 * If "alwaysignore" isn't set, turn it on and off		 * around the "copy" command so it will have the		 * same effect as the "print" command.		 */		if (!mt_value("alwaysignore"))			mt_mail_cmd(			    "set alwaysignore\ncopy %d %s\nunset alwaysignore",			    msg, file);		else			mt_mail_cmd("copy %d %s", msg, file);	} else {		/*		 * If "alwaysignore" is set, turn it off and on		 * around the "copy" command so it will have the		 * same effect as the "Print" command.		 */		if (mt_value("alwaysignore"))			mt_mail_cmd(			    "unset alwaysignore\ncopy %d %s\nset alwaysignore",			    msg, file);		else			mt_mail_cmd("copy %d %s", msg, file);	}	(void)chmod(file, 0600);}/* * Preserve the specified message. */voidmt_preserve_msg(msg)	int             msg;{	mt_mail_cmd("preserve %d", msg);}/* * Delete the specified message. */voidmt_del_msg(msg)	int             msg;{	int             i, len;	(void)unlink(mt_msgfile);	mt_mail_cmd("delete %d", msg);	mt_message[msg].m_deleted = TRUE;	len = mt_message[msg+1].m_start - mt_message[msg].m_start;	for (i = msg + 1; i <= mt_maxmsg + 1; i++) {		mt_message[i].m_start -= len;		mt_message[i].m_lineno--;	}	mt_del_count++;}/* * Undelete the specified message. */voidmt_undel_msg(msg)	int             msg;{	int             i, len;	mt_mail_cmd("undelete %d", msg);	mt_message[msg].m_deleted = FALSE;	len = strlen(mt_message[msg].m_header);	for (i = msg + 1; i <= mt_maxmsg + 1; i++) {		mt_message[i].m_start += len;		mt_message[i].m_lineno++;	}	mt_del_count--;}/* * Switch Mail to the specified folder. * Return number of messages in folder, -1 on failure. */intmt_set_folder(file)	char           *file;{	register char  *p;	int             n = -1;	mt_mail_start_cmd("file %s", file);/*	while (mt_mail_get_line()) {*/	while (MT_MAIL_GET_LINE) {		/* look for '"file" complete' */		if ((p = index(line, '\0') - strlen("complete\n")) >= line &&		    strcmp(p, "complete\n") == 0)			continue;		/* look for '"file" removed' */		if ((p = index(line, '\0') - strlen("removed\n")) >= line &&		    strcmp(p, "removed\n") == 0)			continue;		/* look for '"file": n messages' */		if (line[0] == '"'			&& (p = index(&line[1], '"'))			&& *++p == ':') 			n = atoi(++p);		(void)strcpy(mt_info, line);	}	return (n);}/* incorporates mail into system mail box */intmt_incorporate_mail(){	mt_mail_cmd("inc");	if (strcmp(mt_info, "Unknown command: \"inc\"\n") == 0) {		return (FALSE);	}	return (TRUE);}/* * Find the next message after msg.  If none after, * use specified message if not deleted.  Otherwise, * find first one before msg.  If none, return 0. */intmt_next_msg(msg)	int             msg;{	register int    i;	for (i = msg + mt_scandir; i <= mt_maxmsg && i > 0; i += mt_scandir)		if (!mt_message[i].m_deleted)			return (i);	if (!mt_message[msg].m_deleted && msg != mt_curmsg)		return (msg);	for (i = msg - mt_scandir; i <= mt_maxmsg && i > 0; i -= mt_scandir)		if (!mt_message[i].m_deleted) {			if (mt_value("allowreversescan"))				mt_scandir = -mt_scandir;			return (i);		}	return (0);}/* * Delete a folder. */voidmt_del_folder(file)	char           *file;{	mt_mail_cmd("echo %s", file);	mt_info[strlen(mt_info) - 1] = '\0';	(void)unlink(mt_info);}/* * Do a simple Mail command. *//* VARARGS1 */voidmt_mail_cmd(cmd, a1, a2, a3)	char           *cmd, *a1, *a2, *a3;{	register int    first = TRUE;	mt_talking_to_Mail = TRUE;	/* so mt_broken_pipe can distinguish					 * SIGPIPEs that come from attempts					 * to talk to Mail from spurious					 * SIGPIPEs */	(void)fprintf(mt_mailin, cmd, a1, a2, a3);	(void)fprintf(mt_mailin, "\necho \004\n");	(void)fflush(mt_mailin);/***	produces copious output	if (mt_debugging) {		(void)printf("sent:\n");		(void)printf(cmd, a1, a2, a3);		(void)printf("\necho \\004\n");		(void)printf("received:\n");	} ***/ 	while (fgets(line, LINE_SIZE, mt_mailout)) {		if (strcmp(line, "\004\n") == 0) {/***			if (mt_debugging) 				(void)printf("\\004\n"); ***/			break;		} else if (first) {			(void)strcpy(mt_info, line);			first = FALSE;		}/***		if (mt_debugging) 			(void)printf(line); ***/	}	mt_talking_to_Mail = FALSE;}/* * Start a long Mail command. *//* VARARGS1 */voidmt_mail_start_cmd(cmd,a1,a2,a3)	char           *cmd, *a1, *a2, *a3;{	mt_talking_to_Mail = TRUE;	/* so mt_broken_pipe can distinguish					 * SIGPIPEs that come from attempts					 * to talk to Mail from spurious					 * SIGPIPEs */	(void)fprintf(mt_mailin, cmd, a1, a2, a3);	(void)fprintf(mt_mailin, "\necho \004\n");/***	produces copious output	if (mt_debugging) {		(void)printf("sent:\n");		(void)printf(cmd, a1, a2, a3);		(void)printf("\necho \\004\n");	} ***/	(void)fflush(mt_mailin);/***	if (mt_debugging)		(void)printf("received:\n"); ***/}/* * Read one line of the response from a long * Mail command, checking for end of output. *//*char *mt_mail_get_line(){	if (fgets(line, LINE_SIZE, mt_mailout) == NULL) {		mt_talking_to_Mail = FALSE;		return (NULL);	}	if (strcmp(line, "\004\n") == 0) {		mt_talking_to_Mail = FALSE;		return (NULL);	}	return (line);}*/

⌨️ 快捷键说明

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