aboutsummaryrefslogtreecommitdiff
path: root/src/mime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mime.c')
-rw-r--r--src/mime.c57
1 files changed, 25 insertions, 32 deletions
diff --git a/src/mime.c b/src/mime.c
index 4dfcae5..a41bf40 100644
--- a/src/mime.c
+++ b/src/mime.c
@@ -152,8 +152,8 @@ static int mime_global_wrp(lua_State *L)
152static void b64setup(UC *b64unbase) 152static void b64setup(UC *b64unbase)
153{ 153{
154 int i; 154 int i;
155 for (i = 0; i < 255; i++) b64unbase[i] = 255; 155 for (i = 0; i <= 255; i++) b64unbase[i] = (UC) 255;
156 for (i = 0; i < 64; i++) b64unbase[b64base[i]] = i; 156 for (i = 0; i < 64; i++) b64unbase[b64base[i]] = (UC) i;
157 b64unbase['='] = 0; 157 b64unbase['='] = 0;
158} 158}
159 159
@@ -191,7 +191,7 @@ static size_t b64pad(const UC *input, size_t size,
191 luaL_Buffer *buffer) 191 luaL_Buffer *buffer)
192{ 192{
193 unsigned long value = 0; 193 unsigned long value = 0;
194 UC code[4] = "===="; 194 UC code[4] = {'=', '=', '=', '='};
195 switch (size) { 195 switch (size) {
196 case 1: 196 case 1:
197 value = input[0] << 4; 197 value = input[0] << 4;
@@ -480,38 +480,31 @@ static int mime_global_qp(lua_State *L)
480* Accumulate characters until we are sure about how to deal with them. 480* Accumulate characters until we are sure about how to deal with them.
481* Once we are sure, output the to the buffer, in the correct form. 481* Once we are sure, output the to the buffer, in the correct form.
482\*-------------------------------------------------------------------------*/ 482\*-------------------------------------------------------------------------*/
483static size_t qpdecode(UC c, UC *input, size_t size, 483static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) {
484 luaL_Buffer *buffer) 484 int d;
485{
486 input[size++] = c; 485 input[size++] = c;
487 /* deal with all characters we can deal */ 486 /* deal with all characters we can deal */
488 while (size > 0) { 487 switch (input[0]) {
489 int c, d; 488 /* if we have an escape character */
490 switch (input[0]) { 489 case '=':
491 /* if we have an escape character */ 490 if (size < 3) return size;
492 case '=': 491 /* eliminate soft line break */
493 if (size < 3) return size; 492 if (input[1] == '\r' && input[2] == '\n') return 0;
494 /* eliminate soft line break */ 493 /* decode quoted representation */
495 if (input[1] == '\r' && input[2] == '\n') return 0; 494 c = qpunbase[input[1]]; d = qpunbase[input[2]];
496 /* decode quoted representation */ 495 /* if it is an invalid, do not decode */
497 c = qpunbase[input[1]]; d = qpunbase[input[2]]; 496 if (c > 15 || d > 15) luaL_addlstring(buffer, (char *)input, 3);
498 /* if it is an invalid, do not decode */ 497 else luaL_putchar(buffer, (c << 4) + d);
499 if (c > 15 || d > 15) luaL_addlstring(buffer, (char *)input, 3); 498 return 0;
500 else luaL_putchar(buffer, (c << 4) + d); 499 case '\r':
501 return 0; 500 if (size < 2) return size;
502 case '\r': 501 if (input[1] == '\n') luaL_addlstring(buffer, (char *)input, 2);
503 if (size < 2) return size; 502 return 0;
504 if (input[1] == '\n') luaL_addlstring(buffer, (char *)input, 2); 503 default:
505 return 0; 504 if (input[0] == '\t' || (input[0] > 31 && input[0] < 127))
506 default: 505 luaL_putchar(buffer, input[0]);
507 if (input[0] == '\t' || (input[0] > 31 && input[0] < 127)) 506 return 0;
508 luaL_putchar(buffer, input[0]);
509 return 0;
510 }
511 input[0] = input[1]; input[1] = input[2];
512 size--;
513 } 507 }
514 return 0;
515} 508}
516 509
517/*-------------------------------------------------------------------------*\ 510/*-------------------------------------------------------------------------*\