Mercurial > pidgin.yaz
comparison src/protocols/msn/msn.c @ 3195:92a763567ddc
[gaim-migrate @ 3212]
An MSN mail checking fix, and formatting of incoming msn messages.
Not yet a privacy fix, or initiating group chats--I'll do those later tonight.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Fri, 03 May 2002 19:22:44 +0000 |
parents | 1c351bbdebf0 |
children | c98dc4884ea3 |
comparison
equal
deleted
inserted
replaced
3194:fdd20785e1e1 | 3195:92a763567ddc |
---|---|
352 { | 352 { |
353 char login_url[2048]; | 353 char login_url[2048]; |
354 char buf[MSN_BUF_LEN]; | 354 char buf[MSN_BUF_LEN]; |
355 struct msn_data *md = gc->proto_data; | 355 struct msn_data *md = gc->proto_data; |
356 | 356 |
357 g_snprintf(buf, sizeof(buf), "URL %d INBOX\r\n", ++md->trId); | 357 if (!md->passport) { |
358 | 358 g_snprintf(buf, sizeof(buf), "URL %d INBOX\r\n", ++md->trId); |
359 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | 359 |
360 return; | 360 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
361 } | |
362 | |
363 debug_printf("\n"); | |
364 | |
365 snprintf(login_url, sizeof(login_url), "%s", md->passport); | |
366 | |
367 if (strstr(data, "Content-Type: text/x-msmsgsinitialemailnotification;")) { | |
368 char *x = strstr(data, "Inbox-Unread:"); | |
369 if (!x) return; | |
370 x += strlen("Inbox-Unread: "); | |
371 connection_has_mail(gc, atoi(x), NULL, NULL, login_url); | |
372 } else if (strstr(data, "Content-Type: text/x-msmsgsemailnotification;")) { | |
373 char *from = strstr(data, "From:"); | |
374 char *subject = strstr(data, "Subject:"); | |
375 char *x; | |
376 if (!from || !subject) { | |
377 connection_has_mail(gc, 1, NULL, NULL, login_url); | |
378 return; | 361 return; |
379 } | 362 } |
380 from += strlen("From: "); | 363 } else { |
381 x = strstr(from, "\r\n"); *x = 0; | 364 g_snprintf(login_url, sizeof(login_url), "%s", md->passport); |
382 subject += strlen("Subject: "); | 365 |
383 x = strstr(subject, "\r\n"); *x = 0; | 366 if (strstr(data, "Content-Type: text/x-msmsgsinitialemailnotification;")) { |
384 connection_has_mail(gc, -1, from, subject, login_url); | 367 char *x = strstr(data, "Inbox-Unread:"); |
368 if (!x) return; | |
369 x += strlen("Inbox-Unread: "); | |
370 connection_has_mail(gc, atoi(x), NULL, NULL, login_url); | |
371 } else if (strstr(data, "Content-Type: text/x-msmsgsemailnotification;")) { | |
372 char *from = strstr(data, "From:"); | |
373 char *subject = strstr(data, "Subject:"); | |
374 char *x; | |
375 if (!from || !subject) { | |
376 connection_has_mail(gc, 1, NULL, NULL, login_url); | |
377 return; | |
378 } | |
379 from += strlen("From: "); | |
380 x = strstr(from, "\r\n"); *x = 0; | |
381 subject += strlen("Subject: "); | |
382 x = strstr(subject, "\r\n"); *x = 0; | |
383 connection_has_mail(gc, -1, from, subject, login_url); | |
384 } | |
385 } | 385 } |
386 } | 386 } |
387 | 387 |
388 static struct msn_switchboard *msn_find_switch(struct gaim_connection *gc, char *id) | 388 static struct msn_switchboard *msn_find_switch(struct gaim_connection *gc, char *id) |
389 { | 389 { |
570 } | 570 } |
571 | 571 |
572 return 1; | 572 return 1; |
573 } | 573 } |
574 | 574 |
575 static void msn_unescape(char *text) { | |
576 char *cpy = g_strdup(text); | |
577 char *cur = cpy; | |
578 int c = 0; | |
579 | |
580 | |
581 while (*cur) { | |
582 if (*cur == '%') { | |
583 if (sscanf (cur, "%%%x;", &c) == 1 && c != 0) { | |
584 *text = c; | |
585 cur = cur + 3; | |
586 } | |
587 } else { | |
588 *text = *cur; | |
589 cur++; | |
590 } | |
591 text++; | |
592 } | |
593 *text = 0; | |
594 g_free(cpy); | |
595 } | |
596 | |
597 static char *msn_parse_format(char *mime) | |
598 { | |
599 char *cur; | |
600 GString *ret = g_string_new(NULL); | |
601 char colors[3]; | |
602 | |
603 cur = strstr(mime, "FN="); | |
604 if (cur && (*(cur = cur + 3) != ';')) { | |
605 ret = g_string_append(ret, "<FONT FACE=\""); | |
606 while (*cur && *cur != ';') { | |
607 ret = g_string_append_c(ret, *cur); | |
608 cur++; | |
609 } | |
610 ret = g_string_append(ret, "\">"); | |
611 } | |
612 | |
613 cur = strstr(mime, "EF="); | |
614 if (cur && (*(cur = cur + 3) != ';')) { | |
615 while (*cur && *cur != ';') { | |
616 ret = g_string_append_c(ret, '<'); | |
617 ret = g_string_append_c(ret, *cur); | |
618 ret = g_string_append_c(ret, '>'); | |
619 cur++; | |
620 } | |
621 } | |
622 | |
623 cur = strstr(mime, "CO="); | |
624 if (cur && (*(cur = cur + 3) != ';')) { | |
625 if (sscanf (cur, "%x;", (int*)(&colors)) == 1) { | |
626 char tag[MSN_BUF_LEN]; | |
627 g_snprintf(tag, sizeof(tag), "<FONT COLOR=\"#%02hhx%02hhx%02hhx\">", colors[0], colors[1], colors[2]); | |
628 ret = g_string_append(ret, tag); | |
629 } | |
630 } | |
631 | |
632 msn_unescape(ret->str); | |
633 cur = ret->str; | |
634 g_string_free(ret, FALSE); | |
635 return cur; | |
636 } | |
637 | |
638 | |
575 static void msn_process_switch_msg(struct msn_switchboard *ms, char *msg) | 639 static void msn_process_switch_msg(struct msn_switchboard *ms, char *msg) |
576 { | 640 { |
577 char *content, *agent, *utf; | 641 char *content, *agent, *format, *utf; |
642 char *message = NULL; | |
578 int flags = 0; | 643 int flags = 0; |
579 | 644 |
580 agent = strstr(msg, "User-Agent: "); | 645 agent = strstr(msg, "User-Agent: "); |
581 if (agent) { | 646 if (agent) { |
582 if (!g_strncasecmp(agent, "User-Agent: Gaim", strlen("User-Agent: Gaim"))) | 647 if (!g_strncasecmp(agent, "User-Agent: Gaim", strlen("User-Agent: Gaim"))) |
583 flags |= IM_FLAG_GAIMUSER; | 648 flags |= IM_FLAG_GAIMUSER; |
584 } | 649 } |
650 | |
651 format = strstr(msg, "X-MMS-IM-Format: "); | |
652 if (format) { | |
653 format = msn_parse_format(format); | |
654 } else { | |
655 format = NULL; | |
656 } | |
657 | |
585 content = strstr(msg, "Content-Type: "); | 658 content = strstr(msg, "Content-Type: "); |
586 if (!content) | 659 if (!content) |
587 return; | 660 return; |
588 if (!g_strncasecmp(content, "Content-Type: text/x-msmsgscontrol\r\n", | 661 if (!g_strncasecmp(content, "Content-Type: text/x-msmsgscontrol\r\n", |
589 strlen( "Content-Type: text/x-msmsgscontrol\r\n"))) { | 662 strlen( "Content-Type: text/x-msmsgscontrol\r\n"))) { |
592 return; | 665 return; |
593 } | 666 } |
594 | 667 |
595 } else if (!g_strncasecmp(content, "Content-Type: text/plain", | 668 } else if (!g_strncasecmp(content, "Content-Type: text/plain", |
596 strlen("Content-Type: text/plain"))) { | 669 strlen("Content-Type: text/plain"))) { |
670 | |
671 | |
672 | |
597 char *skiphead; | 673 char *skiphead; |
598 skiphead = strstr(msg, "\r\n\r\n"); | 674 skiphead = strstr(msg, "\r\n\r\n"); |
599 if (!skiphead || !skiphead[4]) { | 675 if (!skiphead || !skiphead[4]) { |
600 return; | 676 return; |
601 } | 677 } |
602 skiphead += 4; | 678 skiphead += 4; |
603 utf = utf8_to_str(skiphead); | 679 utf = utf8_to_str(skiphead); |
604 strip_linefeed(utf); | 680 strip_linefeed(utf); |
605 | 681 |
682 if (format) { | |
683 int len = strlen(utf) + strlen(format) + 1; | |
684 message = g_malloc(len); | |
685 g_snprintf(message, len, "%s%s", format, utf); | |
686 } else { | |
687 message = utf; | |
688 } | |
689 | |
606 if (ms->chat) | 690 if (ms->chat) |
607 serv_got_chat_in(ms->gc, ms->chat->id, ms->msguser, flags, utf, time(NULL)); | 691 serv_got_chat_in(ms->gc, ms->chat->id, ms->msguser, flags, message, time(NULL)); |
608 else | 692 else |
609 serv_got_im(ms->gc, ms->msguser, utf, flags, time(NULL), -1); | 693 serv_got_im(ms->gc, ms->msguser, message, flags, time(NULL), -1); |
610 | 694 |
611 g_free(utf); | 695 g_free(message); |
696 if (format) { | |
697 g_free(format); | |
698 g_free(utf); | |
699 } | |
612 } | 700 } |
613 } | 701 } |
614 | 702 |
615 static void msn_switchboard_callback(gpointer data, gint source, GaimInputCondition cond) | 703 static void msn_switchboard_callback(gpointer data, gint source, GaimInputCondition cond) |
616 { | 704 { |
617 struct msn_switchboard *ms = data; | 705 struct msn_switchboard *ms = data; |
618 char buf[MSN_BUF_LEN]; | 706 char buf[MSN_BUF_LEN]; |
619 int cont = 1; | 707 int cont = 1; |
620 int len; | 708 int len; |
621 | 709 |
622 /* This is really stupid and I hate to put this here. */ | 710 /* This is really stupid and I hate to put this here. */ |
623 if (ms->fd != source) | 711 if (ms->fd != source) |
624 ms->fd = source; | 712 ms->fd = source; |
625 | 713 |
626 len = read(ms->fd, buf, sizeof(buf)); | 714 len = read(ms->fd, buf, sizeof(buf)); |
1172 for (i = 0; i < 16; i++) { | 1260 for (i = 0; i < 16; i++) { |
1173 g_snprintf(buf2, sizeof(buf2), "%02x", di[i]); | 1261 g_snprintf(buf2, sizeof(buf2), "%02x", di[i]); |
1174 strcat(sendbuf, buf2); | 1262 strcat(sendbuf, buf2); |
1175 } | 1263 } |
1176 | 1264 |
1177 md->passport = tmpnam(NULL); | 1265 if (md->passport) { |
1266 unlink(md->passport); | |
1267 free(md->passport); | |
1268 } | |
1269 md->passport = tempnam(NULL, NULL); | |
1178 | 1270 |
1179 fd = fopen(md->passport, "w"); | 1271 fd = fopen(md->passport, "w"); |
1180 fprintf(fd, "<html>\n"); | 1272 fprintf(fd, "<html>\n"); |
1181 fprintf(fd, "<head>\n"); | 1273 fprintf(fd, "<head>\n"); |
1182 fprintf(fd, "<noscript>\n"); | 1274 fprintf(fd, "<noscript>\n"); |
1684 if (md->inpa) | 1776 if (md->inpa) |
1685 gaim_input_remove(md->inpa); | 1777 gaim_input_remove(md->inpa); |
1686 g_free(md->rxqueue); | 1778 g_free(md->rxqueue); |
1687 if (md->msg) | 1779 if (md->msg) |
1688 g_free(md->msguser); | 1780 g_free(md->msguser); |
1781 if (md->passport) { | |
1782 unlink(md->passport); | |
1783 free(md->passport); | |
1784 } | |
1689 while (md->switches) | 1785 while (md->switches) |
1690 msn_kill_switch(md->switches->data); | 1786 msn_kill_switch(md->switches->data); |
1691 while (md->fl) { | 1787 while (md->fl) { |
1692 struct msn_buddy *tmp = md->fl->data; | 1788 struct msn_buddy *tmp = md->fl->data; |
1693 md->fl = g_slist_remove(md->fl, tmp); | 1789 md->fl = g_slist_remove(md->fl, tmp); |