struct addrinfo * camel_getaddrinfo(const char *name, const char *service, const struct addrinfo *hints, CamelException *ex) { struct _addrinfo_msg *msg; struct addrinfo *res = NULL; #ifndef ENABLE_IPv6 struct addrinfo myhints; #endif g_return_val_if_fail(name != NULL, NULL); if (camel_operation_cancel_check(NULL)) { camel_exception_set(ex, CAMEL_EXCEPTION_USER_CANCEL, _("Canceled")); return NULL; } camel_operation_start_transient(NULL, _("Resolving: %s"), name); /* force ipv4 addresses only */ #ifndef ENABLE_IPv6 if (hints == NULL) memset(&myhints, 0, sizeof(myhints)); else memcpy (&myhints, hints, sizeof (myhints)); myhints.ai_family = AF_INET; hints = &myhints; #endif msg = g_malloc0(sizeof(*msg)); msg->name = name; msg->service = service; msg->hints = hints; msg->res = &res; #ifdef NEED_ADDRINFO msg->hostbuflen = 1024; msg->hostbufmem = g_malloc(msg->hostbuflen); #endif if (cs_waitinfo(cs_getaddrinfo, msg, _("Host lookup failed"), ex) == 0) { if (msg->result != 0) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Host lookup failed: %s: %s"), name, gai_strerror (msg->result)); } cs_freeinfo(msg); } else res = NULL; camel_operation_end(NULL); return res; }
int camel_getnameinfo(const struct sockaddr *sa, socklen_t salen, char **host, char **serv, int flags, CamelException *ex) { struct _addrinfo_msg *msg; int result; if (camel_operation_cancel_check(NULL)) { camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, _("Canceled")); return -1; } camel_operation_start_transient(NULL, _("Resolving address")); msg = g_malloc0(sizeof(*msg)); msg->addr = sa; msg->addrlen = salen; if (host) { msg->hostlen = NI_MAXHOST; msg->host = g_malloc(msg->hostlen); msg->host[0] = 0; } if (serv) { msg->servlen = NI_MAXSERV; msg->serv = g_malloc(msg->servlen); msg->serv[0] = 0; } msg->flags = flags; #ifdef NEED_ADDRINFO msg->hostbuflen = 1024; msg->hostbufmem = g_malloc(msg->hostbuflen); #endif cs_waitinfo(cs_getnameinfo, msg, _("Name lookup failed"), ex); if ((result = msg->result) != 0) camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Name lookup failed: %s"), gai_strerror (result)); else { if (host) *host = g_strdup(msg->host); if (serv) *serv = g_strdup(msg->serv); } g_free(msg->host); g_free(msg->serv); g_free(msg); camel_operation_end(NULL); return result; }
static void offline_folder_downsync (CamelOfflineFolder *offline, const char *expression, CamelException *ex) { CamelFolder *folder = (CamelFolder *) offline; CamelMimeMessage *message; GPtrArray *uids; int i; camel_operation_start (NULL, _("Syncing messages in folder '%s' to disk"), folder->full_name); if (expression) uids = camel_folder_search_by_expression (folder, expression, ex); else uids = camel_folder_get_uids (folder); if (!uids) { camel_operation_end (NULL); return; } for (i = 0; i < uids->len; i++) { int pc = i * 100 / uids->len; message = camel_folder_get_message (folder, uids->pdata[i], ex); camel_operation_progress (NULL, pc); if (message == NULL) break; camel_object_unref (message); } if (expression) camel_folder_search_free (folder, uids); else camel_folder_free_uids (folder, uids); camel_operation_end (NULL); }
gboolean subscribe_method(gchar *url) { add_feed *feed = g_new0(add_feed, 1); feed->feed_url = url; feed->add=1; feed->enabled=feed->validate=1; feed->fetch_html = 0; if (feed->feed_url && strlen(feed->feed_url)) { g_print("New Feed received: %s\n", url); feed->feed_url = sanitize_url(feed->feed_url); d("sanitized feed URL: %s\n", feed->feed_url); if (g_hash_table_find(rf->hr, check_if_match, feed->feed_url)) { rss_error(NULL, NULL, _("Error adding feed."), _("Feed already exists!")); //return FALSE; /* we return true here since org.gnome.feed.Reader * doesn't support status */ return TRUE; } if (setup_feed(feed)) { gchar *msg = g_strdup_printf(_("Importing URL: %s"), feed->feed_url); taskbar_push_message(msg); g_free(msg); } if (rf->treeview) store_redraw(GTK_TREE_VIEW(rf->treeview)); save_gconf_feed(); #if (DATASERVER_VERSION >= 2033001) camel_operation_pop_message (NULL); #else camel_operation_end(NULL); #endif } g_free(url); return TRUE; }
static void offline_downsync_sync (CamelSession *session, CamelSessionThreadMsg *mm) { struct _offline_downsync_msg *m = (struct _offline_downsync_msg *) mm; CamelMimeMessage *message; int i; camel_operation_start (NULL, _("Downloading new messages for offline mode")); if (m->changes) { for (i = 0; i < m->changes->uid_added->len; i++) { int pc = i * 100 / m->changes->uid_added->len; camel_operation_progress (NULL, pc); if ((message = camel_folder_get_message (m->folder, m->changes->uid_added->pdata[i], &mm->ex))) camel_object_unref (message); } } else { camel_offline_folder_downsync ((CamelOfflineFolder *) m->folder, "(match-all)", &mm->ex); } camel_operation_end (NULL); }
void camel_disco_diary_replay (CamelDiscoDiary *diary, CamelException *ex) { guint32 action; off_t size; double pc; d(printf("disco diary replay\n")); fseek (diary->file, 0, SEEK_END); size = ftell (diary->file); g_return_if_fail (size != 0); rewind (diary->file); camel_operation_start (NULL, _("Resynchronizing with server")); while (!camel_exception_is_set (ex)) { pc = ftell (diary->file) / size; camel_operation_progress (NULL, pc * 100); if (camel_file_util_decode_uint32 (diary->file, &action) == -1) break; if (action == CAMEL_DISCO_DIARY_END) break; switch (action) { case CAMEL_DISCO_DIARY_FOLDER_EXPUNGE: { CamelFolder *folder; GPtrArray *uids; folder = diary_decode_folder (diary); uids = diary_decode_uids (diary); if (!uids) goto lose; if (folder) camel_disco_folder_expunge_uids (folder, uids, ex); free_uids (uids); break; } case CAMEL_DISCO_DIARY_FOLDER_APPEND: { CamelFolder *folder; char *uid, *ret_uid; CamelMimeMessage *message; CamelMessageInfo *info; folder = diary_decode_folder (diary); if (camel_file_util_decode_string (diary->file, &uid) == -1) goto lose; if (!folder) { g_free (uid); continue; } message = camel_folder_get_message (folder, uid, NULL); if (!message) { /* The message was appended and then deleted. */ g_free (uid); continue; } info = camel_folder_get_message_info (folder, uid); camel_folder_append_message (folder, message, info, &ret_uid, ex); camel_folder_free_message_info (folder, info); if (ret_uid) { camel_disco_diary_uidmap_add (diary, uid, ret_uid); g_free (ret_uid); } g_free (uid); break; } case CAMEL_DISCO_DIARY_FOLDER_TRANSFER: { CamelFolder *source, *destination; GPtrArray *uids, *ret_uids; guint32 delete_originals; int i; source = diary_decode_folder (diary); destination = diary_decode_folder (diary); uids = diary_decode_uids (diary); if (!uids) goto lose; if (camel_file_util_decode_uint32 (diary->file, &delete_originals) == -1) goto lose; if (!source || !destination) { free_uids (uids); continue; } camel_folder_transfer_messages_to (source, uids, destination, &ret_uids, delete_originals, ex); if (ret_uids) { for (i = 0; i < uids->len; i++) { if (!ret_uids->pdata[i]) continue; camel_disco_diary_uidmap_add (diary, uids->pdata[i], ret_uids->pdata[i]); g_free (ret_uids->pdata[i]); } g_ptr_array_free (ret_uids, TRUE); } free_uids (uids); break; } } } lose: camel_operation_end (NULL); /* Close folders */ g_hash_table_foreach (diary->folders, close_folder, diary); g_hash_table_destroy (diary->folders); diary->folders = NULL; /* Truncate the log */ ftruncate (fileno (diary->file), 0); }
static void import_mbox_exec (struct _import_mbox_msg *m) { CamelFolder *folder; CamelMimeParser *mp = NULL; struct stat st; int fd; CamelMessageInfo *info; if (g_stat(m->path, &st) == -1) { g_warning("cannot find source file to import '%s': %s", m->path, g_strerror(errno)); return; } if (m->uri == NULL || m->uri[0] == 0) folder = mail_component_get_folder(NULL, MAIL_COMPONENT_FOLDER_INBOX); else folder = mail_tool_uri_to_folder(m->uri, CAMEL_STORE_FOLDER_CREATE, &m->base.ex); if (folder == NULL) return; if (S_ISREG(st.st_mode)) { CamelOperation *oldcancel = NULL; fd = g_open(m->path, O_RDONLY|O_BINARY, 0); if (fd == -1) { g_warning("cannot find source file to import '%s': %s", m->path, g_strerror(errno)); goto fail1; } mp = camel_mime_parser_new(); camel_mime_parser_scan_from(mp, TRUE); if (camel_mime_parser_init_with_fd(mp, fd) == -1) { /* will never happen - 0 is unconditionally returned */ goto fail2; } if (m->cancel) oldcancel = camel_operation_register(m->cancel); camel_operation_start(NULL, _("Importing `%s'"), folder->full_name); camel_folder_freeze(folder); while (camel_mime_parser_step(mp, NULL, NULL) == CAMEL_MIME_PARSER_STATE_FROM) { CamelMimeMessage *msg; const char *tmp; int pc = 0; guint32 flags = 0; if (st.st_size > 0) pc = (int)(100.0 * ((double)camel_mime_parser_tell(mp) / (double)st.st_size)); camel_operation_progress(NULL, pc); msg = camel_mime_message_new(); if (camel_mime_part_construct_from_parser((CamelMimePart *)msg, mp) == -1) { /* set exception? */ camel_object_unref(msg); break; } info = camel_message_info_new(NULL); tmp = camel_medium_get_header((CamelMedium *)msg, "X-Mozilla-Status"); if (tmp) flags |= decode_mozilla_status(tmp); tmp = camel_medium_get_header((CamelMedium *)msg, "Status"); if (tmp) flags |= decode_status(tmp); tmp = camel_medium_get_header((CamelMedium *)msg, "X-Status"); if (tmp) flags |= decode_status(tmp); camel_message_info_set_flags(info, flags, ~0); camel_folder_append_message(folder, msg, info, NULL, &m->base.ex); camel_message_info_free(info); camel_object_unref(msg); if (camel_exception_is_set(&m->base.ex)) break; camel_mime_parser_step(mp, NULL, NULL); } camel_folder_sync(folder, FALSE, NULL); camel_folder_thaw(folder); camel_operation_end(NULL); /* TODO: these api's are a bit weird, registering the old is the same as deregistering */ if (m->cancel) camel_operation_register(oldcancel); fail2: camel_object_unref(mp); } fail1: camel_folder_sync(folder, FALSE, NULL); camel_object_unref(folder); }