static void * worker(void *d) { int i; CamelException *ex = camel_exception_new(); CamelStore *store; CamelFolder *folder; for (i=0;i<MAX_LOOP;i++) { store = camel_session_get_store(session, path, ex); camel_exception_clear(ex); folder = camel_store_get_folder(store, "testbox", CAMEL_STORE_FOLDER_CREATE, ex); camel_exception_clear(ex); if (testid == 0) { camel_object_unref(folder); camel_object_unref(store); } else { camel_object_unref(store); camel_object_unref(folder); } } camel_exception_free(ex); return NULL; }
static void mc_setup_local_store(MailComponent *mc) { MailComponentPrivate *p = mc->priv; CamelURL *url; char *tmp; CamelException ex; int i; g_mutex_lock(p->lock); if (p->local_store != NULL) { g_mutex_unlock(p->lock); return; } camel_exception_init(&ex); url = camel_url_new("mbox:", NULL); tmp = g_build_filename (p->base_directory, "local", NULL); camel_url_set_path(url, tmp); g_free(tmp); tmp = camel_url_to_string(url, 0); p->local_store = (CamelStore *)camel_session_get_service(session, tmp, CAMEL_PROVIDER_STORE, &ex); g_free(tmp); if (p->local_store == NULL) goto fail; for (i=0;i<sizeof(mc_default_folders)/sizeof(mc_default_folders[0]);i++) { /* FIXME: should this uri be account relative? */ camel_url_set_fragment(url, mc_default_folders[i].name); mc_default_folders[i].uri = camel_url_to_string(url, 0); mc_default_folders[i].folder = camel_store_get_folder(p->local_store, mc_default_folders[i].name, CAMEL_STORE_FOLDER_CREATE, &ex); camel_exception_clear(&ex); } camel_url_free(url); g_mutex_unlock(p->lock); g_object_ref(mc); camel_object_ref(p->local_store); mail_async_event_emit(p->async_event, MAIL_ASYNC_GUI, (MailAsyncFunc)mc_add_local_store, p->local_store, _("On This Computer"), mc); return; fail: g_mutex_unlock(p->lock); g_warning("Could not setup local store/folder: %s", ex.desc); camel_url_free(url); camel_exception_clear(&ex); }
/** * camel_offline_store_set_network_state: * @store: a #CamelOfflineStore object * @state: the network state * @ex: a #CamelException * * Set the network state to either #CAMEL_OFFLINE_STORE_NETWORK_AVAIL * or #CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL. **/ void camel_offline_store_set_network_state (CamelOfflineStore *store, int state, CamelException *ex) { CamelException lex; CamelService *service = CAMEL_SERVICE (store); gboolean network_state = camel_session_get_network_state (service->session); if (store->state == state) return; camel_exception_init (&lex); if (store->state == CAMEL_OFFLINE_STORE_NETWORK_AVAIL) { /* network available -> network unavailable */ if (network_state) { if (((CamelStore *) store)->folders) { GPtrArray *folders; CamelFolder *folder; int i, sync; sync = camel_url_get_param (((CamelService *) store)->url, "sync_offline") != NULL; folders = camel_object_bag_list (((CamelStore *) store)->folders); for (i = 0; i < folders->len; i++) { folder = folders->pdata[i]; if (CAMEL_CHECK_TYPE (folder, CAMEL_OFFLINE_FOLDER_TYPE) && (sync || ((CamelOfflineFolder *) folder)->sync_offline)) { camel_offline_folder_downsync ((CamelOfflineFolder *) folder, NULL, &lex); camel_exception_clear (&lex); } camel_object_unref (folder); } g_ptr_array_free (folders, TRUE); } camel_store_sync (CAMEL_STORE (store), FALSE, &lex); camel_exception_clear (&lex); } if (!camel_service_disconnect (CAMEL_SERVICE (store), network_state, ex)) return; } else { /* network unavailable -> network available */ if (!camel_service_connect (CAMEL_SERVICE (store), ex)) return; } store->state = state; }
static CamelFolder * diary_decode_folder (CamelDiscoDiary *diary) { CamelFolder *folder; char *name; if (camel_file_util_decode_string (diary->file, &name) == -1) return NULL; folder = g_hash_table_lookup (diary->folders, name); if (!folder) { CamelException ex; char *msg; camel_exception_init (&ex); folder = camel_store_get_folder (CAMEL_STORE (diary->store), name, 0, &ex); if (folder) g_hash_table_insert (diary->folders, name, folder); else { msg = g_strdup_printf (_("Could not open `%s':\n%s\nChanges made to this folder will not be resynchronized."), name, camel_exception_get_description (&ex)); camel_exception_clear (&ex); camel_session_alert_user (camel_service_get_session (CAMEL_SERVICE (diary->store)), CAMEL_SESSION_ALERT_WARNING, msg, FALSE); g_free (msg); g_free (name); } } else g_free (name); return folder; }
CamelNNTPGroupList* camel_nntp_grouplist_fetch (CamelNNTPStore *store, CamelException *ex) { CamelNNTPGroupList *list; list = camel_nntp_get_grouplist_from_file (store, ex); printf ("camel_nntp_get_grouplist_from_file returned %p\n", list); if (!list) { camel_exception_clear (ex); list = camel_nntp_get_grouplist_from_server (store, ex); if (!list) { camel_nntp_grouplist_free (list); } else { list->store = store; camel_nntp_grouplist_save (list, ex); return list; } } return list; }
static send_info_t get_receive_type(const char *url) { CamelProvider *provider; CamelException ex; /* HACK: since mbox is ALSO used for native evolution trees now, we need to fudge this to treat it as a special 'movemail' source */ if (!strncmp(url, "mbox:", 5)) return SEND_RECEIVE; camel_exception_init (&ex); provider = camel_provider_get(url, &ex); camel_exception_clear (&ex); if (!provider) return SEND_INVALID; if (provider->object_types[CAMEL_PROVIDER_STORE]) { if (provider->flags & CAMEL_PROVIDER_IS_STORAGE) return SEND_UPDATE; else return SEND_RECEIVE; } else if (provider->object_types[CAMEL_PROVIDER_TRANSPORT]) { return SEND_SEND; } return SEND_INVALID; }
/** * camel_offline_journal_replay: * @journal: a #CamelOfflineJournal object * @ex: a #CamelException * * Replay all entries in the journal. * * Returns %0 on success (no entry failed to replay) or %-1 on fail **/ int camel_offline_journal_replay (CamelOfflineJournal *journal, CamelException *ex) { EDListNode *entry, *next; CamelException lex; int failed = 0; camel_exception_init (&lex); entry = journal->queue.head; while (entry->next) { next = entry->next; if (CAMEL_OFFLINE_JOURNAL_GET_CLASS (journal)->entry_play (journal, entry, &lex) == -1) { if (failed == 0) camel_exception_xfer (ex, &lex); camel_exception_clear (&lex); failed++; } else { e_dlist_remove (entry); } entry = next; } if (failed > 0) return -1; return 0; }
static TnyMsg * tny_camel_partial_msg_receive_strategy_perform_get_msg_default (TnyMsgReceiveStrategy *self, TnyFolder *folder, TnyHeader *header, GError **err) { TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (folder); TnyMsg *message = NULL; CamelMimeMessage *camel_message = NULL; gchar *id; CamelException ex = CAMEL_EXCEPTION_INITIALISER; CamelFolderReceiveType mtype = CAMEL_FOLDER_RECEIVE_PARTIAL; g_assert (TNY_IS_HEADER (header)); if (!priv->strict_retrieval) mtype = CAMEL_FOLDER_RECEIVE_ANY_OR_PARTIAL; id = tny_header_dup_uid (TNY_HEADER (header)); message = NULL; camel_message = camel_folder_get_message (priv->folder, (const char *) id, mtype, -1, &ex); g_free (id); if (camel_exception_is_set (&ex)) { _tny_camel_exception_to_tny_error (&ex, err); camel_exception_clear (&ex); } else { if (camel_message && CAMEL_IS_OBJECT (camel_message)) { TnyHeader *nheader = NULL; nheader = _tny_camel_msg_header_new (CAMEL_MIME_MESSAGE (camel_message), folder, tny_header_get_date_received (header)); _tny_camel_msg_header_set_decorated (TNY_CAMEL_MSG_HEADER (nheader), header, FALSE); message = tny_camel_msg_new (); _tny_camel_msg_set_received (TNY_CAMEL_MSG (message), tny_header_get_date_received (header)); _tny_camel_msg_set_folder (TNY_CAMEL_MSG (message), folder); TNY_CAMEL_MSG_HEADER (nheader)->old_uid = tny_header_dup_uid (header); _tny_camel_msg_set_header (TNY_CAMEL_MSG (message), nheader); _tny_camel_mime_part_set_part (TNY_CAMEL_MIME_PART (message), CAMEL_MIME_PART (camel_message)); tny_header_set_flag (nheader, TNY_HEADER_FLAG_CACHED); tny_header_set_flag (nheader, TNY_HEADER_FLAG_PARTIAL); g_object_unref (nheader); tny_header_set_flag (header, TNY_HEADER_FLAG_CACHED); tny_header_set_flag (header, TNY_HEADER_FLAG_PARTIAL); } } if (camel_message && CAMEL_IS_OBJECT (camel_message)) camel_object_unref (CAMEL_OBJECT (camel_message)); return message; }
static void refresh_folders_exec (struct _refresh_folders_msg *m) { int i; CamelFolder *folder; CamelException ex = CAMEL_EXCEPTION_INITIALISER; get_folders (m->store, m->folders, m->finfo); for (i=0;i<m->folders->len;i++) { folder = mail_tool_uri_to_folder(m->folders->pdata[i], 0, &ex); if (folder) { camel_folder_refresh_info(folder, &ex); camel_exception_clear(&ex); camel_object_unref(folder); } else if (camel_exception_is_set(&ex)) { g_warning ("Failed to refresh folders: %s", camel_exception_get_description (&ex)); camel_exception_clear (&ex); } if (camel_operation_cancel_check(m->info->cancel)) break; } }
/** * camel_session_alert_user_with_id: * * Like camel_session_alert_user() but constructs and uses a CamelException * with the error ID and the specified message. */ gboolean camel_session_alert_user_with_id (CamelSession *session, CamelSessionAlertType type, ExceptionId id, const gchar* message, gboolean cancel, CamelService *service) { CamelException ex = CAMEL_EXCEPTION_INITIALISER; gboolean result; g_return_val_if_fail (message, FALSE); camel_exception_set (&ex, id, message); result = camel_session_alert_user (session, type, &ex, cancel, service); camel_exception_clear (&ex); return result; }
static void get_folders (CamelStore *store, GPtrArray *folders, CamelFolderInfo *info) { CamelException ex; camel_exception_init (&ex); while (info) { if (camel_store_can_refresh_folder (store, info, &ex)) g_ptr_array_add (folders, g_strdup (info->uri)); camel_exception_clear (&ex); get_folders (store, folders, info->child); info = info->next; } }
static void impl_upgradeFromVersion (PortableServer_Servant servant, const short major, const short minor, const short revision, CORBA_Environment *ev) { MailComponent *component; CamelException ex; component = mail_component_peek (); camel_exception_init (&ex); if (em_migrate (e_get_user_data_dir (), major, minor, revision, &ex) == -1) { GNOME_Evolution_Component_UpgradeFailed *failedex; failedex = GNOME_Evolution_Component_UpgradeFailed__alloc(); failedex->what = CORBA_string_dup(_("Failed upgrading Mail settings or folders.")); failedex->why = CORBA_string_dup(ex.desc); CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Component_UpgradeFailed, failedex); } camel_exception_clear (&ex); }
static void session_thread_msg_free(CamelSession *session, CamelSessionThreadMsg *msg) { g_assert(msg->ops != NULL); d(printf("free message %p session %p\n", msg, session)); CAMEL_SESSION_LOCK(session, thread_lock); g_hash_table_remove(session->priv->thread_active, GINT_TO_POINTER(msg->id)); CAMEL_SESSION_UNLOCK(session, thread_lock); d(printf("free msg, ops->free = %p\n", msg->ops->free)); if (msg->ops->free) msg->ops->free(session, msg); if (msg->op) camel_operation_unref(msg->op); camel_exception_clear(&msg->ex); camel_object_unref(msg->session); g_free(msg); }
static gboolean check_for_connection (CamelService *service, CamelException *ex) { CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (service); CamelGroupwiseStorePrivate *priv = groupwise_store->priv; struct addrinfo hints, *ai; memset (&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; hints.ai_family = PF_UNSPEC; ai = camel_getaddrinfo(priv->server_name, "groupwise", &hints, ex); if (ai == NULL && priv->port != NULL && camel_exception_get_id(ex) != CAMEL_EXCEPTION_USER_CANCEL) { camel_exception_clear (ex); ai = camel_getaddrinfo(priv->server_name, priv->port, &hints, ex); } if (ai == NULL) return FALSE; camel_freeaddrinfo (ai); return TRUE; }
static int spool_lock(CamelLocalFolder *lf, CamelLockType type, CamelException *ex) { int retry = 0; CamelMboxFolder *mf = (CamelMboxFolder *)lf; CamelSpoolFolder *sf = (CamelSpoolFolder *)lf; mf->lockfd = open(lf->folder_path, O_RDWR, 0); if (mf->lockfd == -1) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot create folder lock on %s: %s"), lf->folder_path, g_strerror (errno)); return -1; } while (retry < CAMEL_LOCK_RETRY) { if (retry > 0) sleep(CAMEL_LOCK_DELAY); camel_exception_clear(ex); if (camel_lock_fcntl(mf->lockfd, type, ex) == 0) { if (camel_lock_flock(mf->lockfd, type, ex) == 0) { if ((sf->lockid = camel_lock_helper_lock(lf->folder_path, ex)) != -1) return 0; camel_unlock_flock(mf->lockfd); } camel_unlock_fcntl(mf->lockfd); } retry++; } close (mf->lockfd); mf->lockfd = -1; return -1; }
int main(int argc, char **argv) { CamelSession *session; CamelStore *store; CamelException *ex; CamelFolder *folder; CamelMimeMessage *msg; int i, j; CamelStream *mbox; CamelFilterDriver *driver; camel_test_init(argc, argv); camel_test_provider_init(1, local_drivers); ex = camel_exception_new(); /* clear out any camel-test data */ system("/bin/rm -rf /tmp/camel-test"); camel_test_start("Simple filtering of mbox"); session = camel_test_session_new ("/tmp/camel-test"); /* todo: cross-check everything with folder_info checks as well */ /* todo: work out how to do imap/pop/nntp tests */ push("getting store"); store = camel_session_get_store(session, "mbox:///tmp/camel-test/mbox", ex); check_msg(!camel_exception_is_set(ex), "getting store: %s", camel_exception_get_description(ex)); check(store != NULL); pull(); push("Creating output folders"); for (i=0; i<ARRAY_LEN(mailboxes); i++) { push("creating %s", mailboxes[i].name); mailboxes[i].folder = folder = camel_store_get_folder(store, mailboxes[i].name, CAMEL_STORE_FOLDER_CREATE, ex); check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); check(folder != NULL); /* we need an empty folder for this to work */ test_folder_counts(folder, 0, 0); pull(); } pull(); /* append a bunch of messages with specific content */ push("creating 100 test message mbox"); mbox = camel_stream_fs_new_with_name("/tmp/camel-test/inbox", O_WRONLY|O_CREAT|O_EXCL, 0600); for (j=0; j<100; j++) { char *content, *subject; push("creating test message"); msg = test_message_create_simple(); content = g_strdup_printf("data%d content\n", j); test_message_set_content_simple((CamelMimePart *)msg, 0, "text/plain", content, strlen(content)); test_free(content); subject = g_strdup_printf("Test%d message%d subject", j, 100-j); camel_mime_message_set_subject(msg, subject); camel_mime_message_set_date(msg, j*60*24, 0); pull(); camel_stream_printf(mbox, "From \n"); check(camel_data_wrapper_write_to_stream((CamelDataWrapper *)msg, mbox) != -1); #if 0 push("appending simple message %d", j); camel_folder_append_message(folder, msg, NULL, ex); check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); pull(); #endif test_free(subject); check_unref(msg, 1); } check(camel_stream_close(mbox) != -1); check_unref(mbox, 1); pull(); push("Building filters"); driver = camel_filter_driver_new(session); camel_filter_driver_set_folder_func(driver, get_folder, NULL); for (i=0; i<ARRAY_LEN(rules); i++) { camel_filter_driver_add_rule(driver, rules[i].name, rules[i].match, rules[i].action); } pull(); push("Executing filters"); camel_filter_driver_set_default_folder(driver, mailboxes[0].folder); camel_filter_driver_filter_mbox(driver, "/tmp/camel-test/inbox", NULL, ex); check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex)); /* now need to check the folder counts/etc */ check_unref(driver, 1); pull(); /* this tests that invalid rules are caught */ push("Testing broken match rules"); for (i=0; i<ARRAY_LEN(brokens); i++) { push("rule %s", brokens[i].match); driver = camel_filter_driver_new(session); camel_filter_driver_set_folder_func(driver, get_folder, NULL); camel_filter_driver_add_rule(driver, brokens[i].name, brokens[i].match, brokens[i].action); camel_filter_driver_filter_mbox(driver, "/tmp/camel-test/inbox", NULL, ex); check(camel_exception_is_set(ex)); camel_exception_clear(ex); check_unref(driver, 1); pull(); } pull(); push("Testing broken action rules"); for (i=0; i<ARRAY_LEN(brokena); i++) { push("rule %s", brokena[i].action); driver = camel_filter_driver_new(session); camel_filter_driver_set_folder_func(driver, get_folder, NULL); camel_filter_driver_add_rule(driver, brokena[i].name, brokena[i].match, brokena[i].action); camel_filter_driver_filter_mbox(driver, "/tmp/camel-test/inbox", NULL, ex); check(camel_exception_is_set(ex)); camel_exception_clear(ex); check_unref(driver, 1); pull(); } pull(); for (i=0; i<ARRAY_LEN(mailboxes); i++) { check_unref(mailboxes[i].folder, 1); } check_unref(store, 1); check_unref(session, 1); camel_exception_free(ex); camel_test_end(); return 0; }
gint main (gint argc, gchar **argv) { CamelSession *session; CamelSMimeContext *ctx; GError **error; CamelCipherValidity *valid; CamelStream *stream1, *stream2, *stream3; GPtrArray *recipients; GByteArray *buf; gchar *before, *after; camel_test_init (argc, argv); ex = camel_exception_new (); /* clear out any camel-test data */ system ("/bin/rm -rf /tmp/camel-test"); session = camel_test_session_new ("/tmp/camel-test"); ctx = camel_smime_context_new (session); camel_test_start ("Test of S/MIME PKCS7 functions"); stream1 = camel_stream_mem_new (); camel_stream_write (stream1, "Hello, I am a test stream.", 25); g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL); stream2 = camel_stream_mem_new (); camel_test_push ("PKCS7 signing"); camel_smime_sign (ctx, "*****@*****.**", CAMEL_CIPHER_HASH_SHA1, stream1, stream2, ex); check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex)); camel_test_pull (); camel_exception_clear (ex); camel_test_push ("PKCS7 verify"); g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL); g_seekable_seek (G_SEEKABLE (stream2), 0, G_SEEK_SET, NULL, NULL); valid = camel_smime_verify (ctx, CAMEL_CIPHER_HASH_SHA1, stream1, stream2, ex); check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex)); check_msg (camel_cipher_validity_get_valid (valid), "%s", camel_cipher_validity_get_description (valid)); camel_cipher_validity_free (valid); camel_test_pull (); g_object_unref (stream1); g_object_unref (stream2); stream1 = camel_stream_mem_new (); stream2 = camel_stream_mem_new (); stream3 = camel_stream_mem_new (); camel_stream_write (stream1, "Hello, I am a test of encryption/decryption.", 44); g_seekable_seek (G_SEEKABLE (stream1), 0, G_SEEK_SET, NULL, NULL); camel_exception_clear (ex); camel_test_push ("PKCS7 encrypt"); recipients = g_ptr_array_new (); g_ptr_array_add (recipients, "*****@*****.**"); camel_smime_encrypt (ctx, FALSE, "*****@*****.**", recipients, stream1, stream2, ex); check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex)); g_ptr_array_free (recipients, TRUE); camel_test_pull (); g_seekable_seek (G_SEEKABLE (stream2), 0, G_SEEK_SET, NULL, NULL); camel_exception_clear (ex); camel_test_push ("PKCS7 decrypt"); camel_smime_decrypt (ctx, stream2, stream3, ex); check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex)); buf = CAMEL_STREAM_MEM (stream1)->buffer; before = g_strndup (buf->data, buf->len); buf = CAMEL_STREAM_MEM (stream3)->buffer; after = g_strndup (buf->data, buf->len); check_msg (string_equal (before, after), "before = '%s', after = '%s'", before, after); g_free (before); g_free (after); camel_test_pull (); g_object_unref (ctx); g_object_unref (session); camel_test_end (); return 0; }
gint main (gint argc, gchar **argv) { CamelSession *session; CamelCipherContext *ctx; GError **error; CamelCipherValidity *valid; CamelMimePart *mime_part; CamelMultipartSigned *mps; CamelMultipartEncrypted *mpe; GPtrArray *recipients; gint ret; camel_test_init (argc, argv); /* clear out any camel-test data */ system ("/bin/rm -rf /tmp/camel-test"); system ("/bin/mkdir /tmp/camel-test"); setenv ("GNUPGHOME", "/tmp/camel-test/.gnupg", 1); /* import the gpg keys */ if ((ret = system ("gpg < /dev/null > /dev/null 2>&1")) == -1) return 77; else if (WEXITSTATUS (ret) == 127) return 77; system ("gpg --import ../data/camel-test.gpg.pub > /dev/null 2>&1"); system ("gpg --import ../data/camel-test.gpg.sec > /dev/null 2>&1"); session = camel_pgp_session_new ("/tmp/camel-test"); ex = camel_exception_new (); ctx = camel_gpg_context_new (session); camel_gpg_context_set_always_trust (CAMEL_GPG_CONTEXT (ctx), TRUE); camel_test_start ("Test of PGP/MIME functions"); mime_part = camel_mime_part_new (); camel_mime_part_set_content (mime_part, test_msg, strlen (test_msg), "text/plain"); camel_mime_part_set_description (mime_part, "Test of PGP/MIME multipart/signed stuff"); camel_test_push ("PGP/MIME signing"); mps = camel_multipart_signed_new (); camel_multipart_signed_sign (mps, ctx, mime_part, "*****@*****.**", CAMEL_CIPHER_HASH_SHA1, ex); check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex)); camel_test_pull (); g_object_unref (mime_part); camel_exception_clear (ex); camel_test_push ("PGP/MIME verify"); valid = camel_multipart_signed_verify (mps, ctx, ex); check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex)); check_msg (camel_cipher_validity_get_valid (valid), "%s", camel_cipher_validity_get_description (valid)); camel_cipher_validity_free (valid); camel_test_pull (); g_object_unref (mps); camel_exception_clear (ex); mime_part = camel_mime_part_new (); camel_mime_part_set_content (mime_part, test_msg, strlen (test_msg), "text/plain"); camel_mime_part_set_description (mime_part, "Test of PGP/MIME multipart/encrypted stuff"); camel_test_push ("PGP/MIME encrypt"); recipients = g_ptr_array_new (); g_ptr_array_add (recipients, "*****@*****.**"); mpe = camel_multipart_encrypted_new (); camel_multipart_encrypted_encrypt (mpe, mime_part, ctx, "*****@*****.**", recipients, ex); check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex)); g_ptr_array_free (recipients, TRUE); camel_test_pull (); camel_exception_clear (ex); g_object_unref (mime_part); camel_test_push ("PGP/MIME decrypt"); mime_part = camel_multipart_encrypted_decrypt (mpe, ctx, ex); check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex)); g_object_unref (mime_part); g_object_unref (mpe); camel_test_pull (); g_object_unref (ctx); g_object_unref (session); camel_test_end (); return 0; }
static gboolean groupwise_auth_loop (CamelService *service, CamelException *ex) { CamelSession *session = camel_service_get_session (service); CamelStore *store = CAMEL_STORE (service); CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (store); CamelGroupwiseStorePrivate *priv = groupwise_store->priv; gboolean authenticated = FALSE; char *uri; EGwConnectionErrors errors; if (priv->use_ssl && !g_str_equal (priv->use_ssl, "never")) uri = g_strconcat ("https://", priv->server_name, ":", priv->port, "/soap", NULL); else uri = g_strconcat ("http://", priv->server_name, ":", priv->port, "/soap", NULL); service->url->passwd = NULL; while (!authenticated) { if (!service->url->passwd && !(store->flags & CAMEL_STORE_PROXY)) { char *prompt; prompt = camel_session_build_password_prompt ( "GroupWise", service->url->user, service->url->host); service->url->passwd = camel_session_get_password (session, service, "Groupwise", prompt, "password", CAMEL_SESSION_PASSWORD_SECRET, ex); g_free (prompt); if (!service->url->passwd) { camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, _("You did not enter a password.")); return FALSE; } } priv->cnc = e_gw_connection_new_with_error_handler (uri, priv->user, service->url->passwd, &errors); if (!E_IS_GW_CONNECTION(priv->cnc) && priv->use_ssl && g_str_equal (priv->use_ssl, "when-possible")) { char *http_uri = g_strconcat ("http://", uri + 8, NULL); priv->cnc = e_gw_connection_new (http_uri, priv->user, service->url->passwd); g_free (http_uri); } if (!E_IS_GW_CONNECTION(priv->cnc)) { if (errors.status == E_GW_CONNECTION_STATUS_INVALID_PASSWORD) { /* We need to un-cache the password before prompting again */ camel_session_forget_password (session, service, "Groupwise", "password", ex); g_free (service->url->passwd); service->url->passwd = NULL; camel_exception_clear (ex); } else { camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, g_strdup (errors.description)); return FALSE; } } else authenticated = TRUE; } return TRUE; }
static CamelFolder * groupwise_get_folder (CamelStore *store, const char *folder_name, guint32 flags, CamelException *ex) { CamelGroupwiseStore *gw_store = CAMEL_GROUPWISE_STORE (store); CamelGroupwiseStorePrivate *priv = gw_store->priv; CamelFolder *folder; CamelGroupwiseSummary *summary; char *container_id, *folder_dir, *storage_path; EGwConnectionStatus status; GList *list = NULL; gboolean done = FALSE, all_ok = TRUE; const char *position = E_GW_CURSOR_POSITION_END; int count = 0, cursor, summary_count = 0; CamelStoreInfo *si = NULL; guint total = 0; folder = groupwise_get_folder_from_disk (store, folder_name, flags, ex); if (folder) { camel_object_ref (folder); return folder; } camel_exception_clear (ex); CAMEL_SERVICE_REC_LOCK (gw_store, connect_lock); if (!camel_groupwise_store_connected (gw_store, ex)) { CAMEL_SERVICE_REC_UNLOCK (gw_store, connect_lock); return NULL; } if (gw_store->current_folder) { camel_object_unref (gw_store->current_folder); gw_store->current_folder = NULL; } if (!E_IS_GW_CONNECTION( priv->cnc)) { if (!groupwise_connect (CAMEL_SERVICE(store), ex)) { CAMEL_SERVICE_REC_UNLOCK (gw_store, connect_lock); return NULL; } } container_id = g_strdup (g_hash_table_lookup (priv->name_hash, folder_name)); storage_path = g_strdup_printf("%s/folders", priv->storage_path); folder_dir = e_path_to_physical (storage_path, folder_name); g_free(storage_path); folder = camel_gw_folder_new (store, folder_name, folder_dir, ex); if (!folder) { CAMEL_SERVICE_REC_UNLOCK (gw_store, connect_lock); camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_INVALID, _("Authentication failed")); g_free (folder_dir); g_free (container_id); return NULL; } g_free (folder_dir); si = camel_store_summary_path ((CamelStoreSummary *)gw_store->summary, folder_name); if (si) { total = si->total; camel_store_summary_info_free ((CamelStoreSummary *)(gw_store)->summary, si); } summary = (CamelGroupwiseSummary *) folder->summary; summary_count = camel_folder_summary_count (folder->summary); if(!summary_count || !summary->time_string) { d(g_print ("\n\n** %s **: No summary as yet : using get cursor request\n\n", folder->name);)
void com_irontec_evosugar(void *ep, EMPopupTargetSelect *t) { CamelException ex = {0}; gchar *folder_name = camel_folder_get_name(t->folder); gboolean folder_is_sent = FALSE; BREAKPOINT; gui.gtkBuilder = gtk_builder_new(); gtk_builder_set_translation_domain(gui.gtkBuilder, GETTEXT_PACKAGE); gtk_builder_add_from_file(gui.gtkBuilder, g_build_filename(PLUGIN_INSTALL_DIR, UI_FILE, NULL), NULL); gui.entry_search = GTK_WIDGET(gtk_builder_get_object(gui.gtkBuilder, "entrySearch")); gui.button_search = GTK_WIDGET(gtk_builder_get_object(gui.gtkBuilder, "buttonSearch")); gui.radio_button_from = GTK_WIDGET(gtk_builder_get_object(gui.gtkBuilder, "radiobuttonFrom")); gui.radio_button_to = GTK_WIDGET(gtk_builder_get_object(gui.gtkBuilder, "radiobuttonTo")); gui.button_submit = GTK_WIDGET(gtk_builder_get_object(gui.gtkBuilder, "buttonAddToSugarCRM")); gui.entry_subject_edit = GTK_WIDGET(gtk_builder_get_object(gui.gtkBuilder, "entryEditSubject")); BREAKPOINT; g_signal_connect(gui.button_search, "clicked", G_CALLBACK(on_button_search_clicked), GTK_ENTRY(gui.entry_search)); g_signal_connect(gui.button_submit, "clicked", G_CALLBACK(on_button_AddToSugarCRM_clicked), NULL); scrm_session.id = scrm_login(gconf_get_username(), gconf_get_password(), gconf_get_server()); if ((g_strcmp0(folder_name, "Sent") == 0) || (g_strcmp0(folder_name, _("Sent")) == 0) ) { folder_is_sent = TRUE; } if (scrm_session.id == NULL || g_strcmp0(scrm_session.id, "-1") == 0) { gui_show_message(_("SugarCRM"), _("Unable to connect: check your connection and settings please.")); } else { BREAKPOINT; msg = camel_folder_get_message(t->folder, t->uids->pdata[0], &ex); util_get_msg_body(msg, &msg_body); if (msg == NULL) { camel_exception_clear(&ex); return; } BREAKPOINT; subject = camel_mime_message_get_subject(msg); gtk_entry_set_text(gui.entry_subject_edit, subject); gui.body_text_view = gtk_builder_get_object(gui.gtkBuilder, "bodyTextView"); model.body_text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gui.body_text_view)); gtk_text_buffer_set_text(model.body_text_buffer, msg_body, -1); from = camel_mime_message_get_from(msg); to = camel_mime_message_get_recipients(msg, CAMEL_RECIPIENT_TYPE_TO); BREAKPOINT; msg_date = camel_mime_message_get_date(msg, NULL); camel_internet_address_get(from, 0, &from_name, &from_addr); camel_internet_address_get(to, 0, &to_name, &to_addr); g_signal_connect(gui.radio_button_from, "pressed", G_CALLBACK(on_radio_group_search_changed), from_addr); gchar *to_search = to_addr; g_signal_connect(gui.radio_button_to, "pressed", G_CALLBACK(on_radio_group_search_changed), to_search); if (folder_is_sent) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui.radio_button_to),TRUE); } BREAKPOINT; GtkWidget *content_box = GTK_WIDGET(gtk_builder_get_object(gui.gtkBuilder, "vboxContents")); GtkWidget *frame_attach = GTK_WIDGET(gtk_builder_get_object(gui.gtkBuilder, "frameAttach")); if (folder_is_sent) { gtk_entry_set_text(gui.entry_search, to_addr); } else { gtk_entry_set_text(gui.entry_search, from_addr); } GtkScrolledWindow *scrolledwindow = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL)); gtk_scrolled_window_set_policy(scrolledwindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); GtkScrolledWindow *scrolledwindow2 = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL)); gtk_scrolled_window_set_policy(scrolledwindow2, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); BREAKPOINT; gtk_container_add(GTK_CONTAINER(content_box), scrolledwindow); gtk_container_add(GTK_CONTAINER(frame_attach), scrolledwindow2); BREAKPOINT; gui.treeview_search = gtk_tree_view_new(); gui.treeview_attach = gtk_tree_view_new(); add_columns_search(GTK_TREE_VIEW(gui.treeview_search)); add_columns_attachment(GTK_TREE_VIEW(gui.treeview_attach)); model.model_attach = util_get_msg_attachments(msg); //gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), model_search); BREAKPOINT; //g_object_unref (G_OBJECT (model_search)); gtk_builder_connect_signals(gui.gtkBuilder, NULL); gtk_tree_view_set_model(GTK_TREE_VIEW(gui.treeview_attach), model.model_attach); gtk_container_add(scrolledwindow, gui.treeview_search); gtk_container_add(scrolledwindow2, gui.treeview_attach); gui.mainwin = GTK_WIDGET(gtk_builder_get_object (gui.gtkBuilder, "addToSugarCRMwindow")); /* * Show the application window */ gtk_widget_show_all(gui.mainwin); //trigger on_button_search_clicked(NULL, gui.entry_search); if (DEBUG_ON) { //g_mem_profile (); } } // end-else comprobar conexion }
/* this should probably take a folder instead of a session ... */ void test_folder_message_ops (CamelSession *session, const gchar *name, gint local, const gchar *mailbox) { CamelStore *store; CamelService *service; CamelFolder *folder; CamelMimeMessage *msg; gint j; gint indexed, max; GPtrArray *uids; CamelMessageInfo *info; GError *error = NULL; max = local ? 2 : 1; for (indexed = 0; indexed < max; indexed++) { gchar *what = g_strdup_printf ("folder ops: %s %s", name, local ? (indexed?"indexed":"non-indexed"):""); gint flags; camel_test_start (what); test_free (what); push ("getting store"); service = camel_session_add_service ( session, name, name, CAMEL_PROVIDER_STORE, &error); check_msg (error == NULL, "adding store: %s", error->message); check (CAMEL_IS_STORE (service)); store = CAMEL_STORE (service); g_clear_error (&error); pull (); push ("creating %sindexed folder", indexed?"":"non-"); if (indexed) flags = CAMEL_STORE_FOLDER_CREATE | CAMEL_STORE_FOLDER_BODY_INDEX; else flags = CAMEL_STORE_FOLDER_CREATE; folder = camel_store_get_folder_sync ( store, mailbox, flags, NULL, &error); /* we can't create mailbox outside of namespace, since we have no api for it, try * using inbox namespace, works for courier */ if (folder == NULL) { gchar *mbox = g_strdup_printf ("INBOX/%s", mailbox); mailbox = mbox; g_clear_error (&error); folder = camel_store_get_folder_sync ( store, mailbox, flags, NULL, &error); } check_msg (error == NULL, "%s", error->message); check (folder != NULL); /* verify empty/can't get nonexistant stuff */ test_folder_counts (folder, 0, 0); test_folder_not_message (folder, "0"); test_folder_not_message (folder, ""); for (j = 0; j < 10; j++) { gchar *content, *subject; push ("creating test message"); msg = test_message_create_simple (); content = g_strdup_printf ("Test message %d contents\n\n", j); test_message_set_content_simple ( (CamelMimePart *) msg, 0, "text/plain", content, strlen (content)); test_free (content); subject = g_strdup_printf ("Test message %d", j); camel_mime_message_set_subject (msg, subject); pull (); push ("appending simple message %d", j); camel_folder_append_message_sync ( folder, msg, NULL, NULL, NULL, &error); check_msg (error == NULL, "%s", error->message); #if 0 /* sigh, this shouldn't be required, but the imap code is too dumb to do it itself */ if (!local) { push ("forcing a refresh of folder updates"); camel_folder_refresh_info (folder, ex); check_msg (error == NULL, "%s", error->message); pull (); } #endif /*if (!local) camel_test_nonfatal ("unread counts dont seem right for imap");*/ test_folder_counts (folder, j + 1, j + 1); /*if (!local) camel_test_fatal ();*/ push ("checking it is in the right uid slot & exists"); uids = camel_folder_get_uids (folder); check (uids != NULL); check (uids->len == j + 1); if (uids->len > j) test_folder_message (folder, uids->pdata[j]); pull (); push ("checking it is the right message (subject): %s", subject); if (uids->len > j) { info = camel_folder_get_message_info (folder, uids->pdata[j]); check (info != NULL); check_msg ( strcmp (camel_message_info_get_subject (info), subject) == 0, "info->subject %s", camel_message_info_get_subject (info)); camel_message_info_unref (info); } camel_folder_free_uids (folder, uids); pull (); test_free (subject); /*if (!local) camel_test_fatal ();*/ check_unref (msg, 1); pull (); } if (local) check_unref (folder, 1); else check_unref (folder, 2); pull (); #if 0 push ("deleting test folder, with messages in it"); camel_store_delete_folder (store, mailbox, ex); check (camel_exception_is_set (ex)); camel_exception_clear (ex); pull (); #endif push ("re-opening folder"); folder = camel_store_get_folder_sync ( store, mailbox, flags, NULL, &error); check_msg (error == NULL, "%s", error->message); check (folder != NULL); g_clear_error (&error); /* verify counts */ test_folder_counts (folder, 10, 10); /* re-check uid's, after a reload */ uids = camel_folder_get_uids (folder); check (uids != NULL); check (uids->len == 10); for (j = 0; j < 10; j++) { gchar *subject = g_strdup_printf ("Test message %d", j); push ("verify reload of %s", subject); test_folder_message (folder, uids->pdata[j]); info = camel_folder_get_message_info (folder, uids->pdata[j]); check_msg ( strcmp (camel_message_info_get_subject (info), subject) == 0, "info->subject %s", camel_message_info_get_subject (info)); test_free (subject); camel_message_info_unref (info); pull (); } push ("deleting first message & expunging"); camel_folder_delete_message (folder, uids->pdata[0]); test_folder_counts (folder, 10, 9); camel_folder_expunge_sync (folder, NULL, &error); check_msg (error == NULL, "%s", error->message); g_clear_error (&error); test_folder_not_message (folder, uids->pdata[0]); test_folder_counts (folder, 9, 9); camel_folder_free_uids (folder, uids); uids = camel_folder_get_uids (folder); check (uids != NULL); check (uids->len == 9); for (j = 0; j < 9; j++) { gchar *subject = g_strdup_printf ("Test message %d", j + 1); push ("verify after expunge of %s", subject); test_folder_message (folder, uids->pdata[j]); info = camel_folder_get_message_info (folder, uids->pdata[j]); check_msg ( strcmp (camel_message_info_get_subject (info), subject) == 0, "info->subject %s", camel_message_info_get_subject (info)); test_free (subject); camel_message_info_unref (info); pull (); } pull (); push ("deleting last message & expunging"); camel_folder_delete_message (folder, uids->pdata[8]); /* sync? */ test_folder_counts (folder, 9, 8); camel_folder_expunge_sync (folder, NULL, &error); check_msg (error == NULL, "%s", error->message); g_clear_error (&error); test_folder_not_message (folder, uids->pdata[8]); test_folder_counts (folder, 8, 8); camel_folder_free_uids (folder, uids); uids = camel_folder_get_uids (folder); check (uids != NULL); check (uids->len == 8); for (j = 0; j < 8; j++) { gchar *subject = g_strdup_printf ("Test message %d", j + 1); push ("verify after expunge of %s", subject); test_folder_message (folder, uids->pdata[j]); info = camel_folder_get_message_info (folder, uids->pdata[j]); check_msg ( strcmp (camel_message_info_get_subject (info), subject) == 0, "info->subject %s", camel_message_info_get_subject (info)); test_free (subject); camel_message_info_unref (info); pull (); } pull (); push ("deleting all messages & expunging"); for (j = 0; j < 8; j++) { camel_folder_delete_message (folder, uids->pdata[j]); } /* sync? */ test_folder_counts (folder, 8, 0); camel_folder_expunge_sync (folder, NULL, &error); check_msg (error == NULL, "%s", error->message); g_clear_error (&error); for (j = 0; j < 8; j++) { test_folder_not_message (folder, uids->pdata[j]); } test_folder_counts (folder, 0, 0); camel_folder_free_uids (folder, uids); pull (); if (local) check_unref (folder, 1); else check_unref (folder, 2); pull (); /* re-opening folder */ if (g_ascii_strcasecmp (mailbox, "INBOX") != 0) { push ("deleting test folder, with no messages in it"); camel_store_delete_folder_sync ( store, mailbox, NULL, &error); check_msg (error == NULL, "%s", error->message); g_clear_error (&error); pull (); } if (!local) { push ("disconneect service"); camel_service_disconnect_sync ( CAMEL_SERVICE (store), TRUE, NULL, &error); check_msg (error == NULL, "%s", error->message); g_clear_error (&error); pull (); } check_unref (store, 1); camel_test_end (); } }
int main (int argc, char **argv) { CamelSession *session; CamelCipherContext *ctx; CamelException *ex; CamelCipherValidity *valid; CamelStream *stream1, *stream2; struct _CamelMimePart *sigpart, *conpart, *encpart, *outpart; CamelDataWrapper *dw; GPtrArray *recipients; GByteArray *buf; char *before, *after; int ret; if (getenv("CAMEL_TEST_GPG") == NULL) return 77; camel_test_init (argc, argv); /* clear out any camel-test data */ system ("/bin/rm -rf /tmp/camel-test"); system ("/bin/mkdir /tmp/camel-test"); setenv ("GNUPGHOME", "/tmp/camel-test/.gnupg", 1); /* import the gpg keys */ if ((ret = system ("gpg < /dev/null > /dev/null 2>&1")) == -1) return 77; else if (WEXITSTATUS (ret) == 127) return 77; g_message ("gpg --import " TEST_DATA_DIR "/camel-test.gpg.pub > /dev/null 2>&1"); system ("gpg --import " TEST_DATA_DIR "/camel-test.gpg.pub > /dev/null 2>&1"); g_message ("gpg --import " TEST_DATA_DIR "/camel-test.gpg.sec > /dev/null 2>&1"); system ("gpg --import " TEST_DATA_DIR "/camel-test.gpg.sec > /dev/null 2>&1"); session = camel_pgp_session_new ("/tmp/camel-test"); ex = camel_exception_new (); ctx = camel_gpg_context_new (session); camel_gpg_context_set_always_trust (CAMEL_GPG_CONTEXT (ctx), TRUE); camel_test_start ("Test of PGP functions"); stream1 = camel_stream_mem_new (); camel_stream_write (stream1, "Hello, I am a test stream.\n", 27); camel_stream_reset (stream1); conpart = camel_mime_part_new(); dw = camel_data_wrapper_new(); camel_data_wrapper_construct_from_stream(dw, stream1); camel_medium_set_content_object((CamelMedium *)conpart, dw); camel_object_unref(stream1); camel_object_unref(dw); sigpart = camel_mime_part_new(); camel_test_push ("PGP signing"); camel_cipher_sign (ctx, "*****@*****.**", CAMEL_CIPHER_HASH_SHA1, conpart, sigpart, ex); if (camel_exception_is_set(ex)) { printf("PGP signing failed assuming non-functional environment\n%s", camel_exception_get_description (ex)); camel_test_pull(); return 77; } camel_test_pull (); camel_exception_clear (ex); camel_test_push ("PGP verify"); valid = camel_cipher_verify (ctx, sigpart, ex); check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex)); check_msg (camel_cipher_validity_get_valid (valid), "%s", camel_cipher_validity_get_description (valid)); camel_cipher_validity_free (valid); camel_test_pull (); camel_object_unref(conpart); camel_object_unref(sigpart); stream1 = camel_stream_mem_new (); camel_stream_write (stream1, "Hello, I am a test of encryption/decryption.", 44); camel_stream_reset (stream1); conpart = camel_mime_part_new(); dw = camel_data_wrapper_new(); camel_stream_reset(stream1); camel_data_wrapper_construct_from_stream(dw, stream1); camel_medium_set_content_object((CamelMedium *)conpart, dw); camel_object_unref(stream1); camel_object_unref(dw); encpart = camel_mime_part_new(); camel_exception_clear (ex); camel_test_push ("PGP encrypt"); recipients = g_ptr_array_new (); g_ptr_array_add (recipients, "*****@*****.**"); camel_cipher_encrypt (ctx, "*****@*****.**", recipients, conpart, encpart, ex); check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex)); g_ptr_array_free (recipients, TRUE); camel_test_pull (); camel_exception_clear (ex); camel_test_push ("PGP decrypt"); outpart = camel_mime_part_new(); valid = camel_cipher_decrypt (ctx, encpart, outpart, ex); check_msg (!camel_exception_is_set (ex), "%s", camel_exception_get_description (ex)); check_msg (valid->encrypt.status == CAMEL_CIPHER_VALIDITY_ENCRYPT_ENCRYPTED, "%s", valid->encrypt.description); stream1 = camel_stream_mem_new(); stream2 = camel_stream_mem_new(); camel_data_wrapper_write_to_stream((CamelDataWrapper *)conpart, stream1); camel_data_wrapper_write_to_stream((CamelDataWrapper *)outpart, stream2); buf = CAMEL_STREAM_MEM (stream1)->buffer; before = g_strndup (buf->data, buf->len); buf = CAMEL_STREAM_MEM (stream2)->buffer; after = g_strndup (buf->data, buf->len); check_msg (string_equal (before, after), "before = '%s', after = '%s'", before, after); g_free (before); g_free (after); camel_object_unref(stream1); camel_object_unref(stream2); camel_object_unref(conpart); camel_object_unref(encpart); camel_object_unref(outpart); camel_test_pull (); camel_object_unref (CAMEL_OBJECT (ctx)); camel_object_unref (CAMEL_OBJECT (session)); camel_test_end (); return 0; }