Rev 4141 | 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 | |||
4139 | hidnplayr | 8 | if ( mailpointer-mailbuffer>9 ) if (strncmp(mailpointer-5,"\n.\n",5)==0) // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a |
3368 | leency | 9 | { |
4139 | hidnplayr | 10 | debug("End of mail detected"); |
11 | mailpointer = mailpointer - 5; |
||
12 | |||
3368 | leency | 13 | if (strstr(mailbuffer, "+OK")!=mailbuffer) |
14 | { |
||
15 | aim = GET_ANSWER_RETR; |
||
16 | mailpointer = mailbuffer; |
||
17 | debug("GET_ANSWER_RETR != +OK, retry GET_ANSWER_RETR"); |
||
18 | return; |
||
19 | } |
||
20 | aim=NULL; |
||
4141 | hidnplayr | 21 | DSBYTE[mailpointer] = '\0'; |
3368 | leency | 22 | debug("Real letter size:"); |
23 | debugi(mailpointer - mailbuffer); |
||
24 | |||
25 | if (strstri(mailbuffer, "quoted-printable")!=0) |
||
26 | { |
||
27 | debug ("getting qp"); |
||
28 | new_buf = malloc(mailpointer-mailbuffer); |
||
29 | qp_decode stdcall (mailbuffer, new_buf, mailpointer-mailbuffer); |
||
30 | if (EAX==-1) debug("Too small buffer to convert QUOTED-PRINTABLE"); |
||
31 | else |
||
32 | { |
||
4141 | hidnplayr | 33 | free(mailbuffer); |
3368 | leency | 34 | mailbuffer = new_buf; |
35 | mailpointer = strlen(mailbuffer) + mailbuffer; |
||
36 | } |
||
3413 | leency | 37 | } |
3368 | leency | 38 | debug ("getting list info"); |
39 | GetHeader(#from, "\nFrom:"); |
||
40 | GetHeader(#to, "\nTo:"); |
||
41 | GetHeader(#date, "\nDate:"); |
||
42 | GetHeader(#subj, "\nSubject:"); |
||
4142 | hidnplayr | 43 | mdata = strstr(mailbuffer, "\n\r") + 3; // 0x0d 0x0a, 0x0a |
3368 | leency | 44 | debug ("converting to dos"); |
45 | ConvertToDOS(mdata, mailbuffer); |
||
46 | FromHTMLtoTXT(); |
||
47 | letter_view.first = letter_view.count = 0; |
||
48 | |||
49 | line_off = mdata; |
||
50 | while (line_off>1) |
||
51 | { |
||
52 | line_off = GetNextLine(line_off); |
||
53 | letter_view.count++; |
||
54 | } |
||
3413 | leency | 55 | atr.SetAtrFromCurr(mail_list.current+1); |
3368 | leency | 56 | DrawMailBox(); |
57 | } |
||
58 | } |
||
59 | |||
60 | void ConvertToDOS(dword inbuf, searchin) |
||
61 | { |
||
62 | dword dos_buf=0; |
||
63 | if (use_iconv==1) |
||
64 | { |
||
65 | cur_charset = CH_CP866; |
||
66 | if (strstri(searchin, "windows-1251")!=0) || (strstri(searchin, "windows1251")!=0) |
||
67 | { dos_buf = ChangeCharset("CP1251", "CP866", inbuf); cur_charset = CH_CP1251;} |
||
68 | else if (strstri(searchin, "koi8-")!=0) |
||
69 | { dos_buf = ChangeCharset("KOI8-RU", "CP866", inbuf); cur_charset = CH_KOI8;} |
||
70 | else if (strstri(searchin, "utf-8")!=0) || (strstri(searchin, "utf8")!=0) |
||
71 | { dos_buf = ChangeCharset("UTF-8", "CP866", inbuf); cur_charset = CH_UTF8;} |
||
72 | else if (strstri(searchin, "iso8859-5")!=0) || (strstri(searchin, "iso-8859-5")!=0) |
||
73 | { dos_buf = ChangeCharset("ISO8859-5", "CP866", inbuf); cur_charset = CH_ISO8859_5;} |
||
74 | else if (strstri(searchin, "windows-1252")!=0) || (strstri(searchin, "windows1252")!=0) |
||
75 | { dos_buf = ChangeCharset("CP1252", "CP866", inbuf); cur_charset = CH_CP1252;} |
||
76 | } |
||
77 | else |
||
78 | { |
||
79 | if (strstri(searchin, "windows-1251")!=0) wintodos( inbuf); else |
||
80 | if (strstri(searchin, "koi8-")!=0) koitodos( inbuf); else |
||
81 | if (strstri(searchin, "utf-8")!=0) utf8rutodos( inbuf); |
||
82 | } |
||
83 | } |
||
84 | |||
85 | |||
86 | void FromHTMLtoTXT() |
||
87 | { |
||
88 | dword cur_chr, txt_buf_srt, txt_buf_end, is_tag=0; |
||
89 | int i; |
||
90 | if (strstri(mdata, "")==0) && (strstri(mailbuffer, "text/html")==0) {debug("no html tags found"); return;} |
||
91 | debug ("converting: html -> txt"); |
||
92 | cur_chr = mdata; |
||
93 | txt_buf_srt = malloc(mailpointer - mailbuffer); |
||
94 | txt_buf_end = txt_buf_srt; |
||
95 | |||
96 | while (cur_chr < mailpointer) |
||
97 | { |
||
98 | if (DSBYTE[cur_chr]=='<') is_tag = 1; |
||
99 | if (!is_tag) |
||
100 | { |
||
101 | DSBYTE[txt_buf_end] = DSBYTE[cur_chr]; |
||
102 | txt_buf_end++; |
||
103 | _END: |
||
104 | } |
||
105 | if (DSBYTE[cur_chr]=='>') is_tag = NULL; |
||
106 | cur_chr++; |
||
107 | } |
||
108 | DSBYTE[txt_buf_end] = '\0'; |
||
109 | strcpy(mdata, txt_buf_srt); |
||
110 | mailpointer = strlen(mailbuffer) + mailbuffer; //тупо везде это ставить |
||
111 | free(txt_buf_srt); |
||
112 | } |
||
113 | |||
114 | |||
115 | dword GetNextLine(dword start_offset) |
||
116 | { |
||
117 | dword off_n = strstr(start_offset, "\n") + 1, //разрыв строки |
||
118 | off_w = letter_view.w / 6 - 2 + start_offset, //max длинна скроки |
||
119 | off_m; |
||
120 | off_m = off_w; |
||
121 | if (off_n < off_w) return off_n; |
||
122 | while (off_m > start_offset) //перенос по словам |
||
123 | { |
||
124 | if (DSBYTE[off_m]==' ') || (DSBYTE[off_m]=='\9') || (DSBYTE[off_m]=='-') return off_m; |
||
125 | off_m--; |
||
126 | } |
||
127 | return off_w; |
||
128 | } |
||
129 | |||
130 | dword CopyBetweenOffsets(dword start, end) //do not forget to free(line) after use |
||
131 | { |
||
132 | dword line, new_line; |
||
133 | if (end <= start) return 0; |
||
134 | line = new_line = malloc(end - start + 3); |
||
135 | while (end > start) |
||
136 | { |
||
137 | DSBYTE[new_line] = DSBYTE[start]; |
||
138 | start++; |
||
139 | new_line++; |
||
140 | } |
||
141 | DSBYTE[new_line] = '\0'; |
||
142 | return line; |
||
143 | } |
||
144 | |||
145 | void GetHeader(dword workstr, searchstr) |
||
146 | { |
||
147 | char tmpbuf[512]; |
||
148 | dword Qoff; |
||
149 | |||
150 | strcpyb(mailbuffer, workstr, searchstr, "\n"); |
||
151 | if (strstri(workstr, "?Q?")) |
||
152 | { |
||
153 | qp_decode stdcall (workstr, #tmpbuf, strlen(workstr)); |
||
154 | ConvertToDOS(#tmpbuf, workstr); |
||
155 | strcpy(workstr, #tmpbuf); |
||
156 | Qoff = strstri(workstr, "?Q?"); |
||
157 | strcpy(workstr, Qoff); |
||
158 | } |
||
159 | if (strstr(workstr, "?B?")) |
||
160 | { |
||
161 | base64_decode stdcall (strstri(workstr, "?B?"), #tmpbuf, strlen(workstr)); |
||
162 | ConvertToDOS(#tmpbuf, workstr); |
||
163 | strcpy(workstr, #tmpbuf); |
||
164 | } |
||
165 | if (strlen(workstr)+10*6-Form.cwidth>0) { workstr=Form.cwidth/6+workstr-12; DSBYTE[workstr]='\0';} |
||
166 | }=>>')>> |