| | 1252 | |
|---|
| | 1253 | static int |
|---|
| | 1254 | hex_to_int (gchar c) |
|---|
| | 1255 | { |
|---|
| | 1256 | return c >= '0' && c <= '9' ? c - '0' |
|---|
| | 1257 | : c >= 'A' && c <= 'F' ? c - 'A' + 10 |
|---|
| | 1258 | : c >= 'a' && c <= 'f' ? c - 'a' + 10 |
|---|
| | 1259 | : -1; |
|---|
| | 1260 | } |
|---|
| | 1261 | |
|---|
| | 1262 | static int |
|---|
| | 1263 | unescape_character (const char *scanner) |
|---|
| | 1264 | { |
|---|
| | 1265 | int first_digit; |
|---|
| | 1266 | int second_digit; |
|---|
| | 1267 | |
|---|
| | 1268 | first_digit = hex_to_int (*scanner++); |
|---|
| | 1269 | if (first_digit < 0) { |
|---|
| | 1270 | return -1; |
|---|
| | 1271 | } |
|---|
| | 1272 | |
|---|
| | 1273 | second_digit = hex_to_int (*scanner++); |
|---|
| | 1274 | if (second_digit < 0) { |
|---|
| | 1275 | return -1; |
|---|
| | 1276 | } |
|---|
| | 1277 | |
|---|
| | 1278 | return (first_digit << 4) | second_digit; |
|---|
| | 1279 | } |
|---|
| | 1280 | |
|---|
| | 1281 | |
|---|
| | 1282 | static char * |
|---|
| | 1283 | unescape_string (const gchar *escaped_string, |
|---|
| | 1284 | const gchar *illegal_characters) |
|---|
| | 1285 | { |
|---|
| | 1286 | const gchar *in; |
|---|
| | 1287 | gchar *out, *result; |
|---|
| | 1288 | gint character; |
|---|
| | 1289 | |
|---|
| | 1290 | if (escaped_string == NULL) { |
|---|
| | 1291 | return NULL; |
|---|
| | 1292 | } |
|---|
| | 1293 | |
|---|
| | 1294 | result = g_malloc (strlen (escaped_string) + 1); |
|---|
| | 1295 | |
|---|
| | 1296 | out = result; |
|---|
| | 1297 | for (in = escaped_string; *in != '\0'; in++) { |
|---|
| | 1298 | character = *in; |
|---|
| | 1299 | if (*in == '%') { |
|---|
| | 1300 | character = unescape_character (in + 1); |
|---|
| | 1301 | |
|---|
| | 1302 | /* Check for an illegal character. We consider '\0' illegal here. */ |
|---|
| | 1303 | if (character <= 0 |
|---|
| | 1304 | || (illegal_characters != NULL |
|---|
| | 1305 | && strchr (illegal_characters, (char)character) != NULL)) { |
|---|
| | 1306 | g_free (result); |
|---|
| | 1307 | return NULL; |
|---|
| | 1308 | } |
|---|
| | 1309 | in += 2; |
|---|
| | 1310 | } |
|---|
| | 1311 | *out++ = (char)character; |
|---|
| | 1312 | } |
|---|
| | 1313 | |
|---|
| | 1314 | *out = '\0'; |
|---|
| | 1315 | g_assert (out - result <= strlen (escaped_string)); |
|---|
| | 1316 | return result; |
|---|
| | 1317 | |
|---|
| | 1318 | } |
|---|
| | 1319 | |
|---|
| 1295 | | str = strchr (url_string, '/'); |
|---|
| 1296 | | |
|---|
| 1297 | | if (str && strlen (str) > 1) { |
|---|
| 1298 | | str++; |
|---|
| 1299 | | str = strchr (str, '/'); |
|---|
| 1300 | | } else |
|---|
| 1301 | | str = NULL; |
|---|
| 1302 | | |
|---|
| 1303 | | if (str && strlen (str) > 1) { |
|---|
| 1304 | | str++; |
|---|
| 1305 | | str = strchr (str, '/'); |
|---|
| 1306 | | } else |
|---|
| 1307 | | str = NULL; |
|---|
| 1308 | | |
|---|
| 1309 | | if (str && strlen (str) > 1) { |
|---|
| 1310 | | str++; |
|---|
| | 1368 | if (strcasestr (url_string, "maildir")) |
|---|
| | 1369 | { |
|---|
| | 1370 | // maildir:/home/xxx/.modest/local_folders#New%20folder/1183044323.16675_6.mindcrime_2_S_2_S |
|---|
| | 1371 | |
|---|
| | 1372 | str = strchr (url_string, '#'); |
|---|
| | 1373 | if (str && strlen (str) > 1) |
|---|
| | 1374 | { |
|---|
| | 1375 | char *nstr; |
|---|
| | 1376 | |
|---|
| | 1377 | nnstr = unescape_string (str, NULL); |
|---|
| | 1378 | if (nnstr && strlen (nnstr) > 1) |
|---|
| | 1379 | { |
|---|
| | 1380 | nnstr++; |
|---|
| | 1381 | nstr = strchr (nnstr, '/'); |
|---|
| | 1382 | if (nstr) |
|---|
| | 1383 | *nstr = '\0'; |
|---|
| | 1384 | } |
|---|
| | 1385 | str = nnstr; |
|---|
| | 1386 | } else |
|---|
| | 1387 | str = NULL; |
|---|
| | 1388 | } else { |
|---|
| | 1389 | str = strchr (url_string, '/'); |
|---|
| | 1390 | |
|---|
| | 1391 | if (str && strlen (str) > 1) { |
|---|
| | 1392 | str++; |
|---|
| | 1393 | str = strchr (str, '/'); |
|---|
| | 1394 | } else |
|---|
| | 1395 | str = NULL; |
|---|
| | 1396 | |
|---|
| | 1397 | if (str && strlen (str) > 1) { |
|---|
| | 1398 | str++; |
|---|
| | 1399 | str = strchr (str, '/'); |
|---|
| | 1400 | } else |
|---|
| | 1401 | str = NULL; |
|---|
| | 1402 | |
|---|
| | 1403 | if (str && strlen (str) > 1) { |
|---|
| | 1404 | char *nstr; |
|---|
| | 1405 | str++; |
|---|
| | 1406 | nstr = strchr (str, '/'); |
|---|
| | 1407 | if (nstr) |
|---|
| | 1408 | *nstr = '\0'; |
|---|
| | 1409 | } else |
|---|
| | 1410 | str = NULL; |
|---|
| | 1411 | } |
|---|
| | 1412 | |
|---|
| | 1413 | if (str) |
|---|
| | 1414 | { |
|---|