Changeset dd43c62
- Timestamp:
- 2015-05-28T05:26:24Z (9 years ago)
- Branches:
- master
- Children:
- faeb521
- Parents:
- 3d31618
- git-author:
- Artem Savkov <artem.savkov@…> (28-03-15 01:23:42)
- git-committer:
- dequis <dx@…> (28-05-15 05:26:24)
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/user-guide/commands.xml
r3d31618 rdd43c62 1023 1023 </bitlbee-setting> 1024 1024 1025 <bitlbee-setting name="notify_handle" type="string" scope="account"> 1026 <default>empty</default> 1027 1028 <description> 1029 <para> 1030 This setting is available for protocols with e-mail notification functionality. If set to empty all e-mail notifications will go to control channel, if set to some string - this will be the name of a contact who will PRIVMSG you on every new notification. 1031 </para> 1032 </description> 1033 1034 </bitlbee-setting> 1035 1036 <bitlbee-setting name="gmail_notifications" type="boolean" scope="account"> 1037 <default>false</default> 1038 1039 <description> 1040 <para> 1041 Same as "mail_notifications" but GMail specific. 1042 </para> 1043 </description> 1044 1045 </bitlbee-setting> 1046 1025 1047 <bitlbee-setting name="message_length" type="integer" scope="account"> 1026 1048 <default>140</default> -
protocols/bee.h
r3d31618 rdd43c62 156 156 G_MODULE_EXPORT void imcb_buddy_msg(struct im_connection *ic, const char *handle, const char *msg, guint32 flags, 157 157 time_t sent_at); 158 G_MODULE_EXPORT void imcb_notify_email(struct im_connection *ic, const char *handle, char *msg, guint32 flags, 159 time_t sent_at); 158 160 159 161 /* bee_chat.c */ -
protocols/bee_user.c
r3d31618 rdd43c62 271 271 } 272 272 273 void imcb_notify_email(struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at) 274 { 275 if (handle != NULL) { 276 imcb_buddy_msg(ic, handle, msg, flags, sent_at); 277 } else { 278 imcb_log(ic, "%s", msg); 279 } 280 } 281 273 282 void imcb_buddy_typing(struct im_connection *ic, const char *handle, uint32_t flags) 274 283 { -
protocols/jabber/iq.c
r3d31618 rdd43c62 27 27 static xt_status jabber_parse_roster(struct im_connection *ic, struct xt_node *node, struct xt_node *orig); 28 28 static xt_status jabber_iq_display_vcard(struct im_connection *ic, struct xt_node *node, struct xt_node *orig); 29 static xt_status jabber_gmail_handle_new(struct im_connection *ic, struct xt_node *node); 29 30 30 31 xt_status jabber_pkt_iq(struct xt_node *node, gpointer data) … … 141 142 (strcmp(s, XMLNS_SI) == 0)) { 142 143 return jabber_si_handle_request(ic, node, c); 144 } else if ((c = xt_find_node(node->children, "new-mail")) && 145 (s = xt_find_attr(c, "xmlns")) && 146 (strcmp(s, XMLNS_GMAILNOTIFY) == 0)) { 147 return jabber_gmail_handle_new(ic, node); 143 148 } else if (!(c = xt_find_node(node->children, "query")) || 144 149 !(s = xt_find_attr(c, "xmlns"))) { … … 342 347 return XT_ABORT; 343 348 } 349 if (jd->flags & JFLAG_GMAILNOTIFY && node == NULL) { 350 jabber_iq_query_server(ic, jd->server, XMLNS_DISCO_INFO); 351 } 344 352 } else if ((jd->flags & (JFLAG_WANT_BIND | JFLAG_WANT_SESSION)) == 0) { 345 353 if (!jabber_get_roster(ic)) { … … 369 377 370 378 return st; 379 } 380 381 xt_status jabber_iq_query_gmail(struct im_connection *ic); 382 383 static xt_status jabber_gmail_handle_new(struct im_connection *ic, struct xt_node *node) 384 { 385 struct xt_node *response; 386 struct jabber_data *jd = ic->proto_data; 387 388 response = jabber_make_packet("iq", "result", g_strdup_printf("%s@%s", jd->username, jd->server), NULL); 389 390 jabber_cache_add(ic, response, NULL); 391 if (!jabber_write_packet(ic, response)) { 392 return XT_ABORT; 393 } 394 395 jabber_iq_query_gmail(ic); 396 397 return XT_HANDLED; 371 398 } 372 399 … … 710 737 } 711 738 739 xt_status jabber_iq_parse_gmail(struct im_connection *ic, struct xt_node *node, struct xt_node *orig); 740 741 xt_status jabber_iq_query_gmail(struct im_connection *ic) 742 { 743 struct xt_node *node, *query; 744 struct jabber_data *jd = ic->proto_data; 745 746 node = xt_new_node("query", NULL, NULL); 747 xt_add_attr(node, "xmlns", XMLNS_GMAILNOTIFY); 748 if (jd->gmail_time) { 749 char *formatted = g_strdup_printf("%" G_GUINT64_FORMAT, (jd->gmail_time + 1)); 750 xt_add_attr(node, "newer-than-time", formatted); 751 g_free(formatted); 752 } 753 if (jd->gmail_tid) { 754 xt_add_attr(node, "newer-than-tid", jd->gmail_tid); 755 } 756 757 if (!(query = jabber_make_packet("iq", "get", jd->me, node))) { 758 imcb_log(ic, "WARNING: Couldn't generate server query"); 759 xt_free_node(node); 760 } 761 762 jabber_cache_add(ic, query, jabber_iq_parse_gmail); 763 764 return jabber_write_packet(ic, query) ? XT_HANDLED : XT_ABORT; 765 } 766 712 767 xt_status jabber_iq_parse_server_features(struct im_connection *ic, struct xt_node *node, struct xt_node *orig); 713 768 … … 729 784 730 785 return jabber_write_packet(ic, query) ? XT_HANDLED : XT_ABORT; 786 } 787 788 xt_status jabber_iq_parse_gmail(struct im_connection *ic, struct xt_node *node, struct xt_node *orig) 789 { 790 struct xt_node *c; 791 struct jabber_data *jd = ic->proto_data; 792 char *xmlns, *from; 793 guint64 l_time = 0; 794 char *tid = NULL; 795 796 if (!(c = xt_find_node(node->children, "mailbox")) || 797 !(from = xt_find_attr(node, "from")) || 798 !(xmlns = xt_find_attr(c, "xmlns")) || 799 (g_strcmp0(xmlns, XMLNS_GMAILNOTIFY) != 0)) { 800 imcb_log(ic, "WARNING: Received incomplete mailbox packet for gmail notify"); 801 return XT_HANDLED; 802 } 803 804 c = c->children; 805 806 while ((c = xt_find_node(c, "mail-thread-info"))) { 807 struct xt_node *thread, *s; 808 char *subject = NULL; 809 char *snippet = NULL; 810 char *msg = NULL; 811 guint64 t_time; 812 813 t_time = g_ascii_strtoull(xt_find_attr(c, "date"), NULL, 10); 814 if (t_time && t_time > l_time) { 815 l_time = t_time; 816 tid = xt_find_attr(c, "tid"); 817 } 818 819 thread = c->children; 820 821 if ((s = xt_find_node(thread, "subject"))) { 822 subject = s->text; 823 } 824 825 if ((s = xt_find_node(thread, "snippet"))) { 826 snippet = s->text; 827 } 828 829 if (subject) { 830 msg = g_strdup_printf("New mail for %s. Subj: %s", from, subject); 831 } else { 832 msg = g_strdup_printf("New mail for %s.", from); 833 } 834 imcb_notify_email(ic, set_getstr(&ic->acc->set, "notify_handle"), msg, 0, 0); 835 836 if (snippet) { 837 imcb_notify_email(ic, set_getstr(&ic->acc->set, "notify_handle"), snippet, 0, 0); 838 } 839 840 c = c->next; 841 g_free(msg); 842 } 843 844 if (l_time && (!jd->gmail_time || l_time > jd->gmail_time)) { 845 jd->gmail_time = l_time; 846 if (tid) { 847 g_free(jd->gmail_tid); 848 jd->gmail_tid = g_strdup(tid); 849 } 850 } 851 852 return XT_HANDLED; 731 853 } 732 854 … … 781 903 c = c->next; 782 904 } 905 906 if (jd->flags & JFLAG_GMAILNOTIFY) { 907 /* search for gmail notification feature */ 908 c = xt_find_node(node->children, "query"); 909 c = c->children; 910 while ((c = xt_find_node(c, "feature"))) { 911 if (strcmp(xt_find_attr(c, "var"), XMLNS_GMAILNOTIFY) == 0) { 912 jabber_iq_query_gmail(ic); 913 } 914 c = c->next; 915 } 916 } 917 783 918 } else if (strcmp(xmlns, XMLNS_BYTESTREAMS) == 0) { 784 919 char *host, *jid, *port_s; -
protocols/jabber/jabber.c
r3d31618 rdd43c62 100 100 101 101 s = set_add(&acc->set, "xmlconsole", "false", set_eval_bool, acc); 102 103 s = set_add(&acc->set, "gmail_notifications", "false", set_eval_bool, acc); 102 104 s->flags |= ACC_SET_OFFLINE_ONLY; 105 106 s = set_add(&acc->set, "notify_handle", NULL, NULL, acc); 107 s->flags |= ACC_SET_OFFLINE_ONLY | SET_NULL_OK; 103 108 104 109 acc->flags |= ACC_FLAG_AWAY_MESSAGE | ACC_FLAG_STATUS_MESSAGE | … … 259 264 imcb_add_buddy(ic, JABBER_XMLCONSOLE_HANDLE, NULL); 260 265 } 266 if (set_getbool(&acc->set, "gmail_notifications")) { 267 jd->flags |= JFLAG_GMAILNOTIFY; 268 if (set_getstr(&acc->set, "notify_handle")) { 269 imcb_add_buddy(ic, set_getstr(&acc->set, "notify_handle"), NULL); 270 } 271 } 261 272 262 273 jabber_generate_id_hash(jd); … … 334 345 g_free(jd->away_message); 335 346 g_free(jd->internal_jid); 347 g_free(jd->gmail_tid); 336 348 g_free(jd->username); 337 349 g_free(jd->me); -
protocols/jabber/jabber.h
r3d31618 rdd43c62 46 46 JFLAG_XMLCONSOLE = 64, /* If the user added an xmlconsole buddy. */ 47 47 JFLAG_STARTTLS_DONE = 128, /* If a plaintext session was converted to TLS. */ 48 JFLAG_GMAILNOTIFY = 256, /* If gmail notification is enabled */ 48 49 49 50 JFLAG_GTALK = 0x100000, /* Is Google Talk, as confirmed by iq discovery */ … … 102 103 const struct jabber_away_state *away_state; 103 104 char *away_message; 105 guint64 gmail_time; 106 char *gmail_tid; 104 107 105 108 md5_state_t cached_id_prefix; … … 224 227 #define XMLNS_DELAY "urn:xmpp:delay" /* XEP-0203 */ 225 228 #define XMLNS_XDATA "jabber:x:data" /* XEP-0004 */ 229 #define XMLNS_GMAILNOTIFY "google:mail:notify" /* Not a XEP */ 226 230 #define XMLNS_CHATSTATES "http://jabber.org/protocol/chatstates" /* XEP-0085 */ 227 231 #define XMLNS_DISCO_INFO "http://jabber.org/protocol/disco#info" /* XEP-0030 */ -
protocols/msn/msn.c
r3d31618 rdd43c62 46 46 s->flags |= ACC_SET_OFFLINE_ONLY; 47 47 48 set_add(&acc->set, "mail_notifications", "false", set_eval_bool, acc); 48 s = set_add(&acc->set, "mail_notifications", "false", set_eval_bool, acc); 49 s->flags |= ACC_SET_OFFLINE_ONLY; 50 51 s = set_add(&acc->set, "notify_handle", NULL, NULL, acc); 52 s->flags |= ACC_SET_OFFLINE_ONLY | SET_NULL_OK; 49 53 50 54 acc->flags |= ACC_FLAG_AWAY_MESSAGE | ACC_FLAG_STATUS_MESSAGE | … … 82 86 msn_ns_connect(ic, server, 83 87 set_getint(&ic->acc->set, "port")); 88 89 if (set_getbool(&acc->set, "mail_notifications") && set_getstr(&acc->set, "notify_handle")) { 90 imcb_add_buddy(ic, set_getstr(&acc->set, "notify_handle"), NULL); 91 } 84 92 } 85 93 -
protocols/msn/ns.c
r3d31618 rdd43c62 394 394 395 395 if (inbox && folders) { 396 imcb_log(ic, 397 "INBOX contains %s new messages, plus %s messages in other folders.", inbox, 398 folders); 396 char *msg = g_strdup_printf( 397 "INBOX contains %s new messages, plus %s messages in other folders.", inbox, 398 folders); 399 imcb_notify_email(ic, set_getstr(&ic->acc->set, "notify_handle"), msg, 0, 0); 400 g_free(msg); 399 401 } 400 402 … … 408 410 409 411 if (from && fromname) { 410 imcb_log(ic, "Received an e-mail message from %s <%s>.", fromname, 411 from); 412 char *msg = g_strdup_printf("Received an e-mail message from %s <%s>.", 413 fromname, from); 414 imcb_notify_email(ic, set_getstr(&ic->acc->set, "notify_handle"), msg, 0, 0); 415 g_free(msg); 412 416 } 413 417 -
protocols/purple/purple.c
r3d31618 rdd43c62 238 238 s = set_add(&acc->set, "mail_notifications", "false", set_eval_bool, acc); 239 239 s->flags |= ACC_SET_OFFLINE_ONLY; 240 241 s = set_add(&acc->set, "notify_handle", NULL, NULL, acc); 242 s->flags |= ACC_SET_OFFLINE_ONLY | SET_NULL_OK; 240 243 } 241 244 … … 332 335 333 336 purple_account_set_enabled(pd->account, "BitlBee", TRUE); 337 338 if (set_getbool(&acc->set, "mail_notifications") && set_getstr(&acc->set, "notify_handle")) { 339 imcb_add_buddy(ic, set_getstr(&acc->set, "notify_handle"), NULL); 340 } 334 341 } 335 342 … … 1254 1261 { 1255 1262 struct im_connection *ic = purple_ic_by_gc(gc); 1256 1257 imcb_log(ic, "Received e-mail from %s for %s: %s <%s>", from, to, subject, url); 1263 char *msg = g_strdup_printf("Received e-mail from %s for %s: %s <%s>", from, to, subject, url); 1264 1265 imcb_notify_email(ic, set_getstr(&ic->acc->set, "notify_handle"), msg, 0, 0); 1266 g_free(msg); 1258 1267 1259 1268 return NULL; -
protocols/yahoo/yahoo.c
r3d31618 rdd43c62 123 123 static void byahoo_init(account_t *acc) 124 124 { 125 set_add(&acc->set, "mail_notifications", "false", set_eval_bool, acc); 125 set_t *s; 126 127 s = set_add(&acc->set, "mail_notifications", "false", set_eval_bool, acc); 128 s->flags |= ACC_SET_OFFLINE_ONLY; 129 130 s = set_add(&acc->set, "notify_handle", NULL, NULL, acc); 131 s->flags |= ACC_SET_OFFLINE_ONLY | SET_NULL_OK; 126 132 127 133 acc->flags |= ACC_FLAG_AWAY_MESSAGE | ACC_FLAG_STATUS_MESSAGE; … … 145 151 yd->y2_id = yahoo_init(acc->user, acc->pass); 146 152 yahoo_login(yd->y2_id, yd->current_status); 153 154 if (set_getbool(&acc->set, "mail_notifications") && set_getstr(&acc->set, "notify_handle")) { 155 imcb_add_buddy(ic, set_getstr(&acc->set, "notify_handle"), NULL); 156 } 147 157 } 148 158 … … 949 959 { 950 960 struct im_connection *ic = byahoo_get_ic_by_id(id); 951 952 if (!set_getbool(&ic->acc->set, "mail_notifications")) { 953 ; /* The user doesn't care. */ 954 } else if (from && subj) { 955 imcb_log(ic, "Received e-mail message from %s with subject `%s'", from, subj); 956 } else if (cnt > 0) { 957 imcb_log(ic, "Received %d new e-mails", cnt); 961 char *msg; 962 963 if (set_getbool(&ic->acc->set, "mail_notifications")) { 964 if (from && subj) { 965 msg = g_strdup_printf("Received e-mail message from %s with subject `%s'", from, subj); 966 } else if (cnt > 0) { 967 msg = g_strdup_printf("Received %d new e-mails", cnt); 968 } 969 970 imcb_notify_email(ic, set_getstr(&ic->acc->set, "notify_handle"), msg, 0, 0); 971 g_free(msg); 958 972 } 959 973 }
Note: See TracChangeset
for help on using the changeset viewer.