JunkBox_Lib  1.10.2
smtp_tool.c
Go to the documentation of this file.
1 
8 #ifdef CPLUSPLUS
9  #undef CPLUSPLUS
10 #endif
11 
12 
13 #include "smtp_tool.h"
14 #include "mime_tool.h"
15 
16 
22 char* get_smtp_rcpt(char* mesg)
23 {
24  char* pp;
25  char* pt;
26  char* pc;
27  char* pa = NULL;
28 
29  pp = awk(mesg, ':', 1);
30  pc = pack_char(pp, ' ');
31  freeNull(pp);
32  if (pc==NULL) return NULL;
33 
34  if (!strcasecmp("RCPT TO", pc)) {
35  pp = (char*)malloc(strlen((const char*)mesg)+1);
36  pt = strstr(mesg, ":");
37  if (pp==NULL || pt==NULL) {
38  if (pc!=NULL) freeNull(pc);
39  if (pp!=NULL) freeNull(pp);
40  return NULL;
41  }
42  memset(pp, 0, strlen((const char*)mesg)+1);
43  memcpy(pp, pt, strlen((const char*)pt));
44 
45  pa = get_smtp_mailbox(pp);
46  freeNull(pp);
47  }
48 
49  freeNull(pc);
50  return pa;
51 }
52 
53 
62 char* get_smtp_mailbox(char* mesg)
63 {
64  int i, j, k, l;
65  char* mb;
66 
67  i = strlen((const char*)mesg);
68  mb = (char*)malloc(i+1);
69  if (mb==NULL) return NULL;
70  memset(mb, 0, i+1);
71 
72  i--;
73  while(i>=0) {
74  if (mesg[i]!=' ' && mesg[i]!='>' && mesg[i]!=CHAR_CR && mesg[i]!=CHAR_LF) break;
75  i--;
76  }
77  l = i;
78 
79  while(i>=0) {
80  if (mesg[i]==':' || mesg[i]=='<' || mesg[i]==' ') break;
81  i--;
82  }
83  k = i + 1;
84 
85  for (i=k, j=0; i<=l; i++) mb[j++] = mesg[i];
86 
87  return mb;
88 }
89 
90 
96 int is_smtp_onecommand(char* mesg, char* com)
97 {
98  int ret = FALSE;
99  char* pp;
100  char* pc;
101 
102  pp = pack_char(mesg, ' ');
103  pc = awk(pp, ' ', 1);
104  freeNull(pp);
105  if (pc==NULL) return FALSE;
106 
107  if (!strncasecmp(com, pc, strlen((const char*)com))) ret = TRUE;
108 
109  freeNull(pc);
110  return ret;
111 }
112 
113 
121 int smtp_check_dot(char* mesg)
122 {
123  static int preDot = OFF;
124  char* p = mesg;
125 
126  if (preDot==ON) { // 文頭で ".\r\n" を探す.
127  if (!strncmp(".\r\n", mesg, 3)) {
128  preDot = OFF;
129  return TRUE;
130  }
131  preDot = OFF;
132  }
133 
134  while(*p!='\0') {
135  if (!strncmp("\r\n", p, 2)) { // 文中で "\r\n" を探す.
136  if (p[2]=='\0') { // 文末で "\r\n" を探す.
137  preDot = ON;
138  return FALSE;
139  }
140  else if (!strncmp("\r\n.\r\n", p, 5)) { // 文中で "\r\n.\r\n" を探す.
141  preDot = OFF;
142  return TRUE;
143  }
144  }
145  p++;
146  }
147  return FALSE;
148 }
149 
#define OFF
Definition: common.h:231
#define TRUE
Definition: common.h:226
#define FALSE
Definition: common.h:223
#define ON
Definition: common.h:230
MIMEツール ヘッダ
char * get_smtp_rcpt(char *mesg)
Definition: smtp_tool.c:22
int is_smtp_onecommand(char *mesg, char *com)
Definition: smtp_tool.c:96
char * get_smtp_mailbox(char *mesg)
Definition: smtp_tool.c:62
int smtp_check_dot(char *mesg)
Definition: smtp_tool.c:121
SMTPツールプログラム ヘッダ
char * awk(char *buf, char cc, int n)
ccを区切り記号として, strのバッファ内の n番目の項目を返す.要 free()
Definition: tools.c:567
#define freeNull(p)
Definition: tools.h:201
#define CHAR_CR
改行
Definition: tools.h:78
#define CHAR_LF
ラインフィード
Definition: tools.h:79
#define pack_char(s, c)
pack_char_len()
Definition: tools.h:236