SMTPツールプログラム. More...
#include "smtp_tool.h"
#include "mime_tool.h"
Go to the source code of this file.
Functions | |
char * | get_smtp_rcpt (char *mesg) |
char * | get_smtp_mailbox (char *mesg) |
int | is_smtp_onecommand (char *mesg, char *com) |
int | smtp_check_dot (char *mesg) |
Definition in file smtp_tool.c.
char* get_smtp_mailbox | ( | char * | mesg | ) |
char* get_smtp_mailbox(char* mesg)
<forward-path> から <mailbox> を返す.see RFC821
RFC821の <mailbox> とは,通常のメールアドレスのこと.
後ろの文字から探索し,(':' || '<' || ' ') 〜 !(' ' && '>' && CR && LF) を取り出す
Definition at line 63 of file smtp_tool.c.
References CHAR_CR, and CHAR_LF.
Referenced by get_smtp_rcpt().
00064 { 00065 int i, j, k, l; 00066 char* mb; 00067 00068 i = strlen((const char*)mesg); 00069 mb = (char*)malloc(i+1); 00070 if (mb==NULL) return NULL; 00071 memset(mb, 0, i+1); 00072 00073 i--; 00074 while(i>=0) { 00075 if (mesg[i]!=' ' && mesg[i]!='>' && mesg[i]!=CHAR_CR && mesg[i]!=CHAR_LF) break; 00076 i--; 00077 } 00078 l = i; 00079 00080 while(i>=0) { 00081 if (mesg[i]==':' || mesg[i]=='<' || mesg[i]==' ') break; 00082 i--; 00083 } 00084 k = i + 1; 00085 00086 for (i=k, j=0; i<=l; i++) mb[j++] = mesg[i]; 00087 00088 return mb; 00089 }
char* get_smtp_rcpt | ( | char * | mesg | ) |
char* get_smtp_rcpt(char* mesg)
mesg から RCPT TO: コマンドを検索し,配送先のメールアドレスを返す.
Definition at line 22 of file smtp_tool.c.
References awk(), freeNull, get_smtp_mailbox(), and pack_char.
00023 { 00024 char* pp; 00025 char* pt; 00026 char* pc; 00027 char* pa = NULL; 00028 00029 pp = awk(mesg, ':', 1); 00030 pc = pack_char(pp, ' '); 00031 freeNull(pp); 00032 if (pc==NULL) return NULL; 00033 00034 if (!strcasecmp("RCPT TO", pc)) { 00035 pp = (char*)malloc(strlen((const char*)mesg)+1); 00036 pt = strstr(mesg, ":"); 00037 if (pp==NULL || pt==NULL) { 00038 freeNull(pc); 00039 freeNull(pp); 00040 return NULL; 00041 } 00042 memset(pp, 0, strlen((const char*)mesg)+1); 00043 memcpy(pp, pt, strlen((const char*)pt)); 00044 00045 pa = get_smtp_mailbox(pp); 00046 freeNull(pp); 00047 } 00048 00049 freeNull(pc); 00050 return pa; 00051 }
int is_smtp_onecommand | ( | char * | mesg, | |
char * | com | |||
) |
int is_smtp_onecommand(char* mesg, char* com)
DATA, RSETなどの空白無し,引数なしのコマンドを識別する.
Definition at line 98 of file smtp_tool.c.
References awk(), FALSE, freeNull, pack_char, and TRUE.
00099 { 00100 int ret = FALSE; 00101 char* pp; 00102 char* pc; 00103 00104 pp = pack_char(mesg, ' '); 00105 pc = awk(pp, ' ', 1); 00106 freeNull(pp); 00107 if (pc==NULL) return FALSE; 00108 00109 if (!strncasecmp(com, pc, strlen((const char*)com))) ret = TRUE; 00110 00111 freeNull(pc); 00112 return ret; 00113 }
int smtp_check_dot | ( | char * | mesg | ) |
int smtp_check_dot(char* mesg)
メールの終わり "@\r@\n.@\r@\n" を探す.
Definition at line 124 of file smtp_tool.c.
References FALSE, OFF, ON, and TRUE.
00125 { 00126 static int preDot = OFF; 00127 char* p = mesg; 00128 00129 if (preDot==ON) { // 文頭で ".\r\n" を探す. 00130 if (!strncmp(".\r\n", mesg, 3)) { 00131 preDot = OFF; 00132 return TRUE; 00133 } 00134 preDot = OFF; 00135 } 00136 00137 while(*p!='\0') { 00138 if (!strncmp("\r\n", p, 2)) { // 文中で "\r\n" を探す. 00139 if (p[2]=='\0') { // 文末で "\r\n" を探す. 00140 preDot = ON; 00141 return FALSE; 00142 } 00143 else if (!strncmp("\r\n.\r\n", p, 5)) { // 文中で "\r\n.\r\n" を探す. 00144 preDot = OFF; 00145 return TRUE; 00146 } 00147 } 00148 p++; 00149 } 00150 00151 return FALSE; 00152 }