annotate plugins/chkmail.c @ 9824:94910b9520cf

[gaim-migrate @ 10695] Really, someone needs to test this and tell me which of these files need to include internal.h committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 22 Aug 2004 17:33:36 +0000
parents a09ffb82aef1
children 61852117568f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
1 /* This is some funky code. It is still being developed by Rob Flynn - rob@linuxpimps.com
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
2 * I recommend not using this code right now. :)
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
3 */
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
4
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 #define GAIM_PLUGINS
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 #include <stdio.h>
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
8 #include <stdlib.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
9 #include <unistd.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
10 #include <string.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
11 #include <netinet/in.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
12 #include <arpa/inet.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
13 #include <sys/socket.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
14 #include <netdb.h>
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
15 #include <netinet/in.h>
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
16 #include <pthread.h>
9821
a09ffb82aef1 [gaim-migrate @ 10692]
Mark Doliner <mark@kingant.net>
parents: 6308
diff changeset
17
a09ffb82aef1 [gaim-migrate @ 10692]
Mark Doliner <mark@kingant.net>
parents: 6308
diff changeset
18 #include "internal.h"
a09ffb82aef1 [gaim-migrate @ 10692]
Mark Doliner <mark@kingant.net>
parents: 6308
diff changeset
19 #include "gtkgaim.h"
a09ffb82aef1 [gaim-migrate @ 10692]
Mark Doliner <mark@kingant.net>
parents: 6308
diff changeset
20
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21 #include "gaim.h"
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
22
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
23 char username[] = "";
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
24 char password[] = "";
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
25 char mailhost[] = "";
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
26 int mailport = 110;
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
27 int state = 0;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
28
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
29 static void *handle = NULL;
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
30 extern GtkWidget *buddies;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
31
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
32 int lastnum = 0;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
33 int orig = 0;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
34 int mytimer;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
35
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
36 void update_mail();
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
37 void check_mail();
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
38
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
39 int num_msgs()
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
40 {
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
41 struct in_addr *sin;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
42 char recv[1024];
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
43 char command[256];
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
44 int fd;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
45 int num = 0;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
46 int step = 0;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
47 int len;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
48
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
49 sin = (struct in_addr *)get_address(mailhost);
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
50 fd = connect_address(sin->s_addr, mailport);
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
51 while ((len = read(fd, recv, 1023))>0) {
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
52 recv[len] = 0;
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
53 if (!strncmp(recv, "-ERR", strlen("-ERR"))) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
54 step = 4;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
55 break;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
56 } else if (!strncmp(recv, "+OK", strlen("+OK"))) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
57 if (step == 3) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
58 if (sscanf(recv, "+OK %d %d\n", &num, &step) != 2)
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
59 break;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
60 g_snprintf(command, sizeof(command), "QUIT\n");
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
61 write(fd, command, strlen(command));
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
62 close(fd);
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
63 return num;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
64 }
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
65
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
66 if (step == 0) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
67 g_snprintf(command, sizeof(command), "USER %s\n", username);
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
68 write(fd, command, strlen(command));
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
69 step = 1;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
70 } else if (step == 1) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
71 g_snprintf(command, sizeof(command), "PASS %s\n", password);
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
72 write(fd, command, strlen(command));
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
73 step = 2;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
74 } else if (step == 2) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
75 g_snprintf(command, sizeof(command), "STAT\n");
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
76 write(fd, command, strlen(command));
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
77 step = 3;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
78 }
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
79 }
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
80 }
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
81 close(fd);
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
82
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
83 return 0;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
84 }
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
85
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
86 void destroy_mail_list()
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
87 {
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
88 GList *list;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
89 GtkWidget *w;
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
90
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
91 list = GTK_TREE(buddies)->children;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
92 while (list) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
93 w = (GtkWidget *)list->data;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
94 if (!strcmp(GTK_LABEL(GTK_BIN(w)->child)->label, _("Mail Server"))) {
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
95 gtk_tree_remove_items(GTK_TREE(buddies), list);
126
b4cd83f1d0b8 [gaim-migrate @ 136]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 124
diff changeset
96 list = GTK_TREE(buddies)->children;
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
97 if (!list)
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
98 break;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
99 }
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
100 list = list->next;
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
101 }
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
102 }
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
103
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
104
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
105 void setup_mail_list()
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
106 {
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
107 GList *list;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
108 GtkWidget *w;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
109 GtkWidget *item;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
110 GtkWidget *tree;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
111 gchar *buf;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
112
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
113 list = GTK_TREE(buddies)->children;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
114
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
115 while (list) {
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
116 w = (GtkWidget *)list->data;
5116
c081a81ee013 [gaim-migrate @ 5479]
Luke Schierer <lschiere@pidgin.im>
parents: 4168
diff changeset
117 if (!strcmp(GTK_LABEL(GTK_BIN(w)->child)->label, _("Mail Server"))) {
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
118 gtk_tree_remove_items(GTK_TREE(buddies), list);
126
b4cd83f1d0b8 [gaim-migrate @ 136]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 124
diff changeset
119 list = GTK_TREE(buddies)->children;
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
120 if (!list)
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
121 break;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
122 }
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
123 list = list->next;
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
124 }
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
125
5116
c081a81ee013 [gaim-migrate @ 5479]
Luke Schierer <lschiere@pidgin.im>
parents: 4168
diff changeset
126 item = gtk_tree_item_new_with_label(_("Mail Server"));
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
127 tree = gtk_tree_new();
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
128 gtk_widget_show(item);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
129 gtk_widget_show(tree);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
130 gtk_tree_append(GTK_TREE(buddies), item);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
131 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), tree);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
132 gtk_tree_item_expand(GTK_TREE_ITEM(item));
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
133
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
134 buf = g_malloc(BUF_LONG);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
135
5116
c081a81ee013 [gaim-migrate @ 5479]
Luke Schierer <lschiere@pidgin.im>
parents: 4168
diff changeset
136 g_snprintf(buf, BUF_LONG, _("%s (%d new/%d total)"), mailhost, lastnum - orig, lastnum);
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
137 item = gtk_tree_item_new_with_label(buf);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
138 g_free(buf);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
139
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
140 gtk_tree_append(GTK_TREE(tree), item);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
141 gtk_widget_show(item);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
142 }
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
143
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
144 void gaim_plugin_init(void *h) {
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
145 handle = h;
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
146
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
147 orig = num_msgs();
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
148 lastnum = orig;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
149
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
150 gaim_signal_connect(handle, event_blist_update, setup_mail_list, NULL);
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
151 setup_mail_list();
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
152
4168
ebfb80bbe1ed [gaim-migrate @ 4397]
Luke Schierer <lschiere@pidgin.im>
parents: 127
diff changeset
153 mytimer = g_timeout_add(30000, check_mail, NULL);
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
154 }
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
155
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
156 void check_mail() {
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
157 pthread_t mail_thread;
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
158 pthread_attr_t attr;
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
159
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
160 if (state == 0) {
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
161 state = 1;
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
162 pthread_attr_init(&attr);
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
163 pthread_create(&mail_thread, &attr, (void *)&update_mail, NULL);
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
164 }
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
165 }
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
166
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
167 void update_mail () {
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
168 int newnum;
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
169
4168
ebfb80bbe1ed [gaim-migrate @ 4397]
Luke Schierer <lschiere@pidgin.im>
parents: 127
diff changeset
170 g_source_remove(mytimer);
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
171
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
172 newnum = num_msgs();
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
173
6308
a21cf07cd8e1 [gaim-migrate @ 6807]
Mark Doliner <mark@kingant.net>
parents: 5116
diff changeset
174 if ((newnum >= lastnum) && (newnum > 0)) {
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
175 newnum = newnum - lastnum;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
176 } else {
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
177 newnum = 0;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
178 }
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
179
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
180 if (newnum < lastnum) {
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
181 orig = lastnum;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
182 }
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
183
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
184 lastnum = newnum;
4168
ebfb80bbe1ed [gaim-migrate @ 4397]
Luke Schierer <lschiere@pidgin.im>
parents: 127
diff changeset
185 mytimer = g_timeout_add(30000, check_mail, NULL);
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
186 setup_mail_list();
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
187 state = 0;
114
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
188 }
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
189
668727c82810 [gaim-migrate @ 124]
Rob Flynn <gaim@robflynn.com>
parents: 105
diff changeset
190
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
191 void gaim_plugin_remove() {
4168
ebfb80bbe1ed [gaim-migrate @ 4397]
Luke Schierer <lschiere@pidgin.im>
parents: 127
diff changeset
192 g_source_remove(mytimer);
127
1330d0c8b1ff [gaim-migrate @ 137]
Rob Flynn <gaim@robflynn.com>
parents: 126
diff changeset
193 while (state == 1) { }
124
5f294f7c4f2e [gaim-migrate @ 134]
Rob Flynn <gaim@robflynn.com>
parents: 114
diff changeset
194 destroy_mail_list();
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
195 handle = NULL;
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
196 }
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
197
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
198 char *name() {
5116
c081a81ee013 [gaim-migrate @ 5479]
Luke Schierer <lschiere@pidgin.im>
parents: 4168
diff changeset
199 return _("Check Mail");
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
200 }
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
201
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
202 char *description() {
5116
c081a81ee013 [gaim-migrate @ 5479]
Luke Schierer <lschiere@pidgin.im>
parents: 4168
diff changeset
203 return _("Check email every X seconds.\n");
105
c76d4c0c5e3a [gaim-migrate @ 115]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
204 }