Rev 4417 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3368 | leency | 1 | //Leency & SoUrcerer, LGPL |
2 | |||
4139 | hidnplayr | 3 | void ParseMail() |
3368 | leency | 4 | { |
5 | dword line_off, new_buf; |
||
6 | char tline[256]; |
||
7 | |||
4417 | leency | 8 | if ( mailend-mailstart > 9) if (strncmp(mailend-5,"\n.\n",5)==0) // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a |
3368 | leency | 9 | { |
4417 | leency | 10 | aim = STOP; |
4166 | leency | 11 | mailend -= 5; |
4186 | leency | 12 | DSBYTE[mailend] = '\0'; |
4166 | leency | 13 | if (strstr(mailstart, "+OK")!=mailstart) |
3368 | leency | 14 | { |
15 | aim = GET_ANSWER_RETR; |
||
4166 | leency | 16 | mailend = mailstart; |
3368 | leency | 17 | debug("GET_ANSWER_RETR != +OK, retry GET_ANSWER_RETR"); |
18 | return; |
||
19 | } |
||
4166 | leency | 20 | mailsize = mailend - mailstart; |
4186 | leency | 21 | debug("Getting QP"); |
4166 | leency | 22 | if (strstri(mailstart, "quoted-printable")!=0) |
3368 | leency | 23 | { |
4186 | leency | 24 | new_buf = malloc(mailsize); |
25 | qp_decode stdcall (mailstart, new_buf, mailsize); |
||
3368 | leency | 26 | if (EAX==-1) debug("Too small buffer to convert QUOTED-PRINTABLE"); |
27 | else |
||
28 | { |
||
4166 | leency | 29 | free(mailstart); |
30 | mailstart = new_buf; |
||
31 | mailsize = strlen(mailstart); |
||
32 | mailend = mailsize + mailstart; |
||
3368 | leency | 33 | } |
3413 | leency | 34 | } |
4417 | leency | 35 | debug("ProcessBase64"); |
36 | ProcessBase64(); |
||
4186 | leency | 37 | debug("GetHeaders: From, To, Date, Subject"); |
3368 | leency | 38 | GetHeader(#from, "\nFrom:"); |
39 | GetHeader(#to, "\nTo:"); |
||
40 | GetHeader(#date, "\nDate:"); |
||
41 | GetHeader(#subj, "\nSubject:"); |
||
4186 | leency | 42 | debug("Get mdata"); |
4417 | leency | 43 | mdata = strstr(mailstart, "\x0a\x0d") + 3; |
4186 | leency | 44 | debug("ConvertToDOS"); |
4166 | leency | 45 | ConvertToDOS(mdata, mailstart); |
4186 | leency | 46 | debug("SetAtrFromCurr"); |
3413 | leency | 47 | atr.SetAtrFromCurr(mail_list.current+1); |
3368 | leency | 48 | DrawMailBox(); |
49 | } |
||
50 | } |
||
51 | |||
52 | void ConvertToDOS(dword inbuf, searchin) |
||
53 | { |
||
54 | dword dos_buf=0; |
||
55 | if (use_iconv==1) |
||
56 | { |
||
57 | cur_charset = CH_CP866; |
||
58 | if (strstri(searchin, "windows-1251")!=0) || (strstri(searchin, "windows1251")!=0) |
||
59 | { dos_buf = ChangeCharset("CP1251", "CP866", inbuf); cur_charset = CH_CP1251;} |
||
60 | else if (strstri(searchin, "koi8-")!=0) |
||
61 | { dos_buf = ChangeCharset("KOI8-RU", "CP866", inbuf); cur_charset = CH_KOI8;} |
||
62 | else if (strstri(searchin, "utf-8")!=0) || (strstri(searchin, "utf8")!=0) |
||
63 | { dos_buf = ChangeCharset("UTF-8", "CP866", inbuf); cur_charset = CH_UTF8;} |
||
64 | else if (strstri(searchin, "iso8859-5")!=0) || (strstri(searchin, "iso-8859-5")!=0) |
||
65 | { dos_buf = ChangeCharset("ISO8859-5", "CP866", inbuf); cur_charset = CH_ISO8859_5;} |
||
66 | else if (strstri(searchin, "windows-1252")!=0) || (strstri(searchin, "windows1252")!=0) |
||
67 | { dos_buf = ChangeCharset("CP1252", "CP866", inbuf); cur_charset = CH_CP1252;} |
||
68 | } |
||
69 | else |
||
70 | { |
||
71 | if (strstri(searchin, "windows-1251")!=0) wintodos( inbuf); else |
||
72 | if (strstri(searchin, "koi8-")!=0) koitodos( inbuf); else |
||
73 | if (strstri(searchin, "utf-8")!=0) utf8rutodos( inbuf); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | |||
78 | dword CopyBetweenOffsets(dword start, end) //do not forget to free(line) after use |
||
79 | { |
||
80 | dword line, new_line; |
||
81 | if (end <= start) return 0; |
||
82 | line = new_line = malloc(end - start + 3); |
||
83 | while (end > start) |
||
84 | { |
||
85 | DSBYTE[new_line] = DSBYTE[start]; |
||
86 | start++; |
||
87 | new_line++; |
||
88 | } |
||
89 | DSBYTE[new_line] = '\0'; |
||
90 | return line; |
||
91 | } |
||
92 | |||
4186 | leency | 93 | |
3368 | leency | 94 | void GetHeader(dword workstr, searchstr) |
95 | { |
||
96 | char tmpbuf[512]; |
||
97 | dword Qoff; |
||
4186 | leency | 98 | int q_start, b_start; |
3368 | leency | 99 | |
4166 | leency | 100 | strcpyb(mailstart, workstr, searchstr, "\n"); |
4417 | leency | 101 | /* |
4186 | leency | 102 | debug(searchstr); |
103 | debug(workstr); |
||
104 | if (strlen(workstr)<8) return; |
||
105 | q_start = strstri(workstr, "?Q?"); |
||
106 | b_start = strstri(workstr, "?B?"); |
||
107 | if (q_start) |
||
3368 | leency | 108 | { |
109 | qp_decode stdcall (workstr, #tmpbuf, strlen(workstr)); |
||
110 | ConvertToDOS(#tmpbuf, workstr); |
||
111 | strcpy(workstr, #tmpbuf); |
||
112 | Qoff = strstri(workstr, "?Q?"); |
||
113 | strcpy(workstr, Qoff); |
||
114 | } |
||
4186 | leency | 115 | |
116 | //any text that goes after "?=" deletes now |
||
117 | if (b_start) |
||
3368 | leency | 118 | { |
4186 | leency | 119 | base64_decode stdcall (b_start, #tmpbuf, strlen(b_start)-5); |
3368 | leency | 120 | ConvertToDOS(#tmpbuf, workstr); |
121 | strcpy(workstr, #tmpbuf); |
||
122 | } |
||
123 | if (strlen(workstr)+10*6-Form.cwidth>0) { workstr=Form.cwidth/6+workstr-12; DSBYTE[workstr]='\0';} |
||
4417 | leency | 124 | */ |
125 | } |
||
126 | |||
127 | |||
128 | |||
129 | void ProcessBase64() |
||
130 | { |
||
131 | int b_start, b_end, b_size, b_buf; |
||
132 | int clean_mailstart; |
||
133 | |||
134 | b_start = strstr(mailstart, "?B?"); |
||
135 | debug("b_size"); |
||
136 | debugi(b_start); |
||
137 | if (b_start) |
||
138 | { |
||
139 | b_end = strstr(b_start, "?="); |
||
140 | debug("b_end"); |
||
141 | debugi(b_end); |
||
142 | b_size = b_end - b_start; |
||
143 | debug("b_size"); |
||
144 | debugi(b_size); |
||
145 | b_buf = malloc(b_size); |
||
146 | strcpyb(mailstart, b_buf, "?B?", "?="); |
||
147 | debug("b_buf"); |
||
148 | debug(b_buf); |
||
149 | |||
150 | base64_decode stdcall (b_buf, b_buf, b_size-3); |
||
151 | ConvertToDOS(b_buf, mailstart); |
||
152 | if (b_size |
||
153 | |||
154 | clean_mailstart = malloc(strlen(mailstart)); |
||
155 | strlcpy(clean_mailstart, mailstart, b_start-mailstart); |
||
156 | strcat(clean_mailstart, b_buf); |
||
157 | strcat(clean_mailstart, b_end+2); |
||
158 | free(b_buf); |
||
159 | free(mailstart); |
||
160 | mailsize = strlen(clean_mailstart); |
||
161 | mailstart = clean_mailstart; |
||
162 | mailend = mailstart + mailsize; |
||
163 | ProcessBase64(); |
||
164 | } |
||
165 | } |
||
166 | |||
167 | |||
168 | //8)>=> |