Exemple #1
0
/**
 * Test whether we can move off distinguished name page.
 * \return <i>TRUE</i> if OK to move off page.
 */
static gboolean exp_ldif_move_dn( void ) {
	gboolean retVal = FALSE;
	gboolean errFlag = FALSE;
	gchar *suffix;
	gint id;

	/* Set suffix */
	suffix = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entrySuffix), 0, -1 );
	g_strchug( suffix ); g_strchomp( suffix );

	/* Set RDN format */
	id = combobox_get_active_data(GTK_COMBO_BOX(expldif_dlg.optmenuRDN));
	exportldif_set_rdn( _exportCtl_, id );

	exportldif_set_suffix( _exportCtl_, suffix );
	exportldif_set_use_dn( _exportCtl_,
		gtk_toggle_button_get_active(
			GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ) ) );
	exportldif_set_exclude_email( _exportCtl_,
		gtk_toggle_button_get_active(
			GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ) ) );

	if( *suffix == '\0' || strlen( suffix ) < 1 ) {
		AlertValue aval;

		aval = alertpanel(
			_( "Suffix was not supplied" ),
			_(
				"A suffix is required if data is to be used " \
				"for an LDAP server. Are you sure you wish " \
				"to proceed without a suffix?"
			 ),
			GTK_STOCK_NO, GTK_STOCK_YES, NULL );
		if( aval != G_ALERTALTERNATE ) {
			gtk_widget_grab_focus( expldif_dlg.entrySuffix );
			errFlag = TRUE;
		}
	}

	if( ! errFlag ) {
		/* Process export */
		exportldif_process( _exportCtl_, _addressCache_ );
		if( _exportCtl_->retVal == MGU_SUCCESS ) {
			retVal = TRUE;
		}
		else {
			export_ldif_status_show( _( "Error creating LDIF file" ) );
		}
	}

	return retVal;
}
Exemple #2
0
static void import_ok_cb(GtkWidget *widget, gpointer data)
{
	const gchar *utf8mbox, *destdir;
	FolderItem *dest;
	gchar *mbox;

	utf8mbox = gtk_entry_get_text(GTK_ENTRY(file_entry));
	destdir = gtk_entry_get_text(GTK_ENTRY(dest_entry));

	if (utf8mbox && !*utf8mbox) {
		alertpanel_error(_("Source mbox filename can't be left empty."));
		gtk_widget_grab_focus(file_entry);
		return;
	}
	if (destdir && !*destdir) {
		if (alertpanel(_("Import mbox file"), _("Destination folder is not set.\nImport mbox file to the Inbox folder?"),
						GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL, ALERTFOCUS_FIRST)
			== G_ALERTALTERNATE) {
			gtk_widget_grab_focus(dest_entry);
			return;
		}
	}

	mbox = g_filename_from_utf8(utf8mbox, -1, NULL, NULL, NULL);
	if (!mbox) {
		g_warning("import_ok_cb(): failed to convert character set.");
		mbox = g_strdup(utf8mbox);
	}

	if (!destdir || !*destdir) {
		dest = folder_find_item_from_path(INBOX_DIR);
	} else {
		dest = folder_find_item_from_identifier
			(destdir);
	}

	if (!dest) {
		alertpanel_error(_("Can't find the destination folder."));
		gtk_widget_grab_focus(dest_entry);
		g_free(mbox);
		return;
	} else {
		import_ok = proc_mbox(dest, mbox, FALSE, NULL);
	}

	g_free(mbox);

	if (gtk_main_level() > 1)
		gtk_main_quit();
}
Exemple #3
0
/**
 * Test whether we can move off file page.
 * \return <i>TRUE</i> if OK to move off page.
 */
static gboolean exp_ldif_move_file( void ) {
	gchar *sFile, *msg, *reason;
	gboolean errFlag = FALSE;
	AlertValue aval;

	sFile = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entryLdif), 0, -1 );
	g_strstrip( sFile );
	gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), sFile );
	exportldif_parse_filespec( _exportCtl_, sFile );

	/* Test that something was supplied */
	if( *sFile == '\0'|| strlen( sFile ) < 1 ) {
		gtk_widget_grab_focus( expldif_dlg.entryLdif );
		errFlag = TRUE;
	}
	g_free( sFile );
	if( errFlag ) return FALSE;

	/* Test for directory */
	if( g_file_test(_exportCtl_->dirOutput,
				G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) {
		return TRUE;
	}

	/* Prompt to create */
	msg = g_strdup_printf( _(
		"LDIF Output Directory '%s'\n" \
		"does not exist. OK to create new directory?" ),
		_exportCtl_->dirOutput );
	aval = alertpanel( _("Create Directory" ),
		msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL );
	g_free( msg );
	if( aval != G_ALERTALTERNATE ) return FALSE;

	/* Create directory */
	if( ! exportldif_create_dir( _exportCtl_ ) ) {
		reason = exportldif_get_create_msg( _exportCtl_ );
		msg = g_strdup_printf( _(
			"Could not create output directory for LDIF file:\n%s" ),
			reason );
		aval = alertpanel_full(_("Failed to Create Directory"), msg,
				       GTK_STOCK_CLOSE, NULL, NULL, FALSE,
				       NULL, ALERT_ERROR, G_ALERTDEFAULT);
		g_free( msg );
		return FALSE;
	}

	return TRUE;
}
Exemple #4
0
/**
 * Callback function to be called before sending the mail.
 * 
 * @param source The composer to be checked.
 * @param data Additional data.
 *
 * @return TRUE if no attachments are mentioned or files are attached,
 *         FALSE if attachments are mentioned and no files are attached.
 */
static gboolean attwarn_before_send_hook(gpointer source, gpointer data)
{
	Compose *compose = (Compose *)source;
	AttachWarnerMention *mention = NULL;

	debug_print("attachwarner invoked\n");
	if (compose->batch)
		return FALSE;	/* do not check while queuing */

	if (do_not_check_redirect_forward(compose->mode))
		return FALSE;

	mention = are_attachments_mentioned(compose); 
	if (does_not_have_attachments(compose) && mention != NULL) { 
		AlertValue aval;
		gchar *button_label;
		gchar *message;
		gchar *bold_text;
		
		debug_print("user has to decide\n");
		if (compose->sending)
			button_label = g_strconcat("+", _("_Send"), NULL);
		else
			button_label = g_strconcat("+", _("_Queue"), NULL);

		bold_text = g_strdup_printf("<span weight=\"bold\">%.20s</span>...",
				mention->context);
		message = g_strdup_printf(
				_("An attachment is mentioned in the mail you're sending, "
				"but no file was attached. Mention appears on line %d, "
				"which begins with text: %s\n\n%s"),
				mention->line,
				bold_text,
				compose->sending?_("Send it anyway?"):_("Queue it anyway?"));
		aval = alertpanel(_("Attachment warning"), message,
				  GTK_STOCK_CANCEL, button_label, NULL);
		g_free(message);
		g_free(bold_text);
		if (aval != G_ALERTALTERNATE)
			return TRUE;
	}
	if (mention != NULL) {
		if (mention->context != NULL)
			g_free(mention->context);
		g_free(mention);
	}

	return FALSE;	/* continue sending */
}
Exemple #5
0
static void prefs_actions_delete_all_cb(gpointer gtk_action, gpointer data)
{
	GtkListStore *list_store;

	if (alertpanel(_("Delete all actions"),
			  _("Do you really want to delete all the actions?"),
			  GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL) != G_ALERTDEFAULT)
	   return;

	list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(actions.actions_list_view)));
	prefs_actions_clear_list(list_store);
	modified = FALSE;

	prefs_actions_reset_dialog();
	modified_list = TRUE;
}
static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
{
  if(prefs_common_get_prefs()->confirm_on_exit) {
    if(alertpanel(_("Exit"), _("Exit Claws Mail?"),
		  GTK_STOCK_CANCEL, GTK_STOCK_OK,
		  NULL) != G_ALERTALTERNATE) {
      return;
    }
    manage_window_focus_in(mainwin->window, NULL, NULL);
  }

  if (prefs_common_get_prefs()->clean_on_exit) {
    if (!main_window_empty_trash(mainwin, prefs_common_get_prefs()->ask_on_clean, TRUE))
      return;
  }

  app_will_exit(NULL, mainwin);
}
Exemple #7
0
static void apply_popup_delete (GtkAction *action, gpointer data)
{
	GtkTreeIter sel;
	GtkTreeModel *model;
	gint id;
	SummaryView *summaryview = NULL;
	GtkTreeSelection *selection = gtk_tree_view_get_selection
				(GTK_TREE_VIEW(applywindow.taglist));
	model = gtk_tree_view_get_model(GTK_TREE_VIEW(applywindow.taglist));

	if (!gtk_tree_selection_get_selected(selection, NULL, &sel))
		return;

	if (alertpanel(_("Delete tag"),
		       _("Do you really want to delete this tag?"),
		       GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL,
					 ALERTFOCUS_FIRST) != G_ALERTALTERNATE)
		return;

	APPLYWINDOW_LOCK();

	/* XXX: Here's the reason why we need to store the original 
	 * pointer: we search the slist for it. */
	gtk_tree_model_get(model, &sel,
			   TAG_DATA, &id,
			   -1);

	/* Even though this is not documented, gtk_tree_model_get()
	 * seems to invalidate the GtkTreeIter that is passed to it,
	 * so we need to reacquire it. */
	if (!gtk_tree_selection_get_selected(selection, NULL, &sel))
		return;

	gtk_list_store_remove(GTK_LIST_STORE(model), &sel);
	if (mainwindow_get_mainwindow() != NULL)
		summaryview = mainwindow_get_mainwindow()->summaryview;
	if (summaryview)
		summary_set_tag(summaryview, -id, NULL);
	tags_remove_tag(id);
	tags_write_tags();
	APPLYWINDOW_UNLOCK();
}
Exemple #8
0
/**
 * Test whether we can move off file page.
 * \return <i>TRUE</i> if OK to move off page.
 */
static gboolean exp_html_move_file( void ) {
	gchar *sFile, *msg, *reason;
	AlertValue aval;

	sFile = gtk_editable_get_chars( GTK_EDITABLE(exphtml_dlg.entryHtml), 0, -1 );
	g_strchug( sFile ); g_strchomp( sFile );
	gtk_entry_set_text( GTK_ENTRY(exphtml_dlg.entryHtml), sFile );
	exporthtml_parse_filespec( _exportCtl_, sFile );
	g_free( sFile );

	/* Test for directory */
	if( exporthtml_test_dir( _exportCtl_ ) ) {
		return TRUE;
	}

	/* Prompt to create */
	msg = g_strdup_printf( _(
		"HTML Output Directory '%s'\n" \
		"does not exist. OK to create new directory?" ),
		_exportCtl_->dirOutput );
	aval = alertpanel( _("Create Directory" ),
		msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL );
	g_free( msg );
	if( aval != G_ALERTALTERNATE ) return FALSE;

	/* Create directory */
	if( ! exporthtml_create_dir( _exportCtl_ ) ) {
		reason = exporthtml_get_create_msg( _exportCtl_ );
		msg = g_strdup_printf( _(
			"Could not create output directory for HTML file:\n%s" ),
			reason );
		aval = alertpanel_full(_("Failed to Create Directory"), msg,
				       GTK_STOCK_CLOSE, NULL, NULL, FALSE,
				       NULL, ALERT_ERROR, G_ALERTDEFAULT);
		g_free( msg );
		return FALSE;
	}

	return TRUE;
}
static void received_event_add_request(gint fd)
{
	gchar *vevent;
	gchar *msg;
	gchar *new_vevent = NULL;

	vevent = get_next_event();

	g_print("Event to add: '%s'\n",vevent);

	if (vevent) {
		AlertValue val;
		val = G_ALERTALTERNATE;
		if (opensync_config.event_ask_add) {
			msg = g_strdup_printf(_("Really add event:\n%s?"),vevent);
			val = alertpanel(_("OpenSync plugin"),msg,
											 GTK_STOCK_CANCEL,GTK_STOCK_ADD,NULL);
			g_free(msg);
		}
		if (!opensync_config.event_ask_add || (val != G_ALERTDEFAULT)) {
			if((new_vevent = vcal_add_event(vevent)) != NULL) {
				g_print("adding successful\n");
			}
			else
				g_print("could not add event\n");
		}
		else {
			g_print("Error: User refused to add event '%s'\n", vevent);
		}
	}
	else {
		g_print("Error: Not able to get the event to add\n");
	}
	if(new_vevent)
		event_send_cb(new_vevent);
	else
		sock_send(fd, ":failure:\n");

	g_free(vevent);
}
static void received_contact_delete_request(gint fd)
{
	gchar buf[BUFFSIZE];
	gboolean delete_successful= FALSE;

	if (fd_gets(fd, buf, sizeof(buf)) != -1) {
		gchar *id;
		ContactHashVal *hash_val;
		id = g_strchomp(buf);
		hash_val = g_hash_table_lookup(contact_hash, id);

		if (hash_val) {
			AlertValue val;
			val = G_ALERTALTERNATE;
			if(opensync_config.contact_ask_delete) {
				gchar *msg;
				msg = g_strdup_printf(_("Really delete contact for '%s'?"),
															ADDRITEM_NAME(hash_val->person));
				val = alertpanel(_("OpenSync plugin"),msg,
												 GTK_STOCK_CANCEL,GTK_STOCK_DELETE,NULL);
				g_free(msg);
			}
			if(((!opensync_config.contact_ask_delete) || (val != G_ALERTDEFAULT)) &&
				 (addrduplicates_delete_item_person(hash_val->person,hash_val->ds))) {
				g_print("Deleted id: '%s'\n", id);
				delete_successful = TRUE;
			}
		}
	}
	if(delete_successful) {
	  sock_send(fd, ":ok:\n");
	}
	else {
	  sock_send(fd, ":failure:\n");
	}
}
Exemple #11
0
static void prefs_themes_btn_install_clicked_cb(GtkWidget *widget, gpointer data)
{
	gchar      *filename, *source;
	gchar 	   *themeinfo, *themename;
	gchar      *alert_title = NULL;
	CopyInfo   *cinfo;
	AlertValue  val = 0;
	ThemesData *tdata = prefs_themes_data;

	filename = filesel_select_file_open_folder(_("Select theme folder"), NULL);
	if (filename == NULL) 
		return;

	if (filename[strlen(filename) - 1] != G_DIR_SEPARATOR)
		filename = g_strconcat(filename, G_DIR_SEPARATOR_S, NULL);
	else
		filename = g_strdup(filename);

	cinfo = g_new0(CopyInfo, 1);
	source = g_path_get_dirname(filename);
	themename = g_path_get_basename(source);
	debug_print("Installing '%s' theme from %s\n", themename, filename);

	themeinfo = g_strconcat(source, G_DIR_SEPARATOR_S, THEMEINFO_FILE, NULL);
	alert_title = g_strdup_printf(_("Install theme '%s'"), themename);
	if (file_exist(themeinfo, FALSE) == FALSE) {
		val = alertpanel(alert_title,
				 _("This folder doesn't seem to be a theme folder.\nInstall anyway?"),
				 GTK_STOCK_NO, GTK_STOCK_YES, NULL);
		if (G_ALERTALTERNATE != val)
			goto end_inst;
	}
	if (superuser_p ()) {
		val = alertpanel(alert_title,
				 _("Do you want to install theme for all users?"),
				 GTK_STOCK_NO, GTK_STOCK_YES, NULL);
		switch (val) {
		case G_ALERTALTERNATE:
			cinfo->dest = stock_pixmap_get_system_theme_dir_for_theme(
						themename);
			break;
		case G_ALERTDEFAULT:
			break;
		default:
			goto end_inst;
		}
	}
	g_free(alert_title);
	if (cinfo->dest == NULL) {
		cinfo->dest = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
					  PIXMAP_THEME_DIR, G_DIR_SEPARATOR_S,
					  themename, NULL);
	}
	if (TRUE == is_dir_exist(cinfo->dest)) {
		AlertValue val = alertpanel_full(_("Theme exists"),
				_("A theme with the same name is\nalready installed in this location.\n\n"
				  "Do you want to replace it?"),
				GTK_STOCK_CANCEL, _("Overwrite"), NULL, FALSE,
				NULL, ALERT_WARNING, G_ALERTDEFAULT);
		if (val == G_ALERTALTERNATE) {
			if (remove_dir_recursive(cinfo->dest) < 0) {
				alertpanel_error(_("Couldn't delete the old theme in %s."), cinfo->dest);
				goto end_inst;
			}
		} else {
			goto end_inst;
		}
	}
	if (0 != make_dir_hier(cinfo->dest)) {
		alertpanel_error(_("Couldn't create destination directory %s."), cinfo->dest);
		goto end_inst;
	}
	prefs_themes_foreach_file(source, prefs_themes_file_install, cinfo);
	if (cinfo->status == NULL) {
		GList *insted;

		/* update interface to show newly installed theme */
		prefs_themes_get_themes_and_names(tdata);
		insted = g_list_find_custom(tdata->themes, 
					    (gpointer)(cinfo->dest), 
					    (GCompareFunc)strcmp2);
		if (NULL != insted) {
			alertpanel_notice(_("Theme installed successfully."));
			tdata->displayed = (gchar *)(insted->data);
			prefs_themes_set_themes_menu(GTK_COMBO_BOX(tdata->page->op_menu), tdata);
			prefs_themes_display_global_stats(tdata);
			prefs_themes_get_theme_info(tdata);
		}
		else
			alertpanel_error(_("Failed installing theme"));
	}
	else
		alertpanel_error(_("File %s failed\nwhile installing theme."), cinfo->status);
end_inst:
	g_free(cinfo->dest);
	g_free(filename);
	g_free(source);
	g_free(themeinfo);
	g_free(cinfo);
	g_free(themename);
}
Exemple #12
0
void sgpgme_create_secret_key(PrefsAccount *account, gboolean ask_create)
{
	AlertValue val = G_ALERTDEFAULT;
	gchar *key_parms = NULL;
	gchar *name = NULL;
	gchar *email = NULL;
	gchar *passphrase = NULL, *passphrase_second = NULL;
	gint prev_bad = 0;
	gchar *tmp = NULL;
	gpgme_error_t err = 0;
	gpgme_ctx_t ctx;
	GtkWidget *window = NULL;
	gpgme_genkey_result_t key;

	if (account == NULL)
		account = account_get_default();

	if (account->address == NULL) {
		alertpanel_error(_("You have to save the account's information with \"OK\" "
				   "before being able to generate a key pair.\n"));
		return;
	}
	if (ask_create) {
		val = alertpanel(_("No PGP key found"),
				_("Claws Mail did not find a secret PGP key, "
				  "which means that you won't be able to sign "
				  "emails or receive encrypted emails.\n"
				  "Do you want to create a new key pair now?"),
				  GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL);
		if (val == G_ALERTDEFAULT) {
			prefs_gpg_get_config()->gpg_ask_create_key = FALSE;
			prefs_gpg_save_config();
			return;
		}
	}

	if (account->name) {
		name = g_strdup(account->name);
	} else {
		name = g_strdup(account->address);
	}
	email = g_strdup(account->address);
	tmp = g_strdup_printf("%s <%s>", account->name?account->name:account->address, account->address);
again:
	passphrase = passphrase_mbox(tmp, NULL, prev_bad, 1);
	if (passphrase == NULL) {
		g_free(tmp);
		g_free(email);
		g_free(name);		
		return;
	}
	passphrase_second = passphrase_mbox(tmp, NULL, 0, 2);
	if (passphrase_second == NULL) {
		g_free(tmp);
		g_free(email);
		g_free(passphrase);		
		g_free(name);		
		return;
	}
	if (strcmp(passphrase, passphrase_second)) {
		g_free(passphrase);
		g_free(passphrase_second);
		prev_bad = 1;
		goto again;
	}
	
	key_parms = g_strdup_printf("<GnupgKeyParms format=\"internal\">\n"
					"Key-Type: RSA\n"
					"Key-Length: 2048\n"
					"Subkey-Type: RSA\n"
					"Subkey-Length: 2048\n"
					"Name-Real: %s\n"
					"Name-Email: %s\n"
					"Expire-Date: 0\n"
					"%s%s%s"
					"</GnupgKeyParms>\n",
					name, email, 
					strlen(passphrase)?"Passphrase: ":"",
					passphrase,
					strlen(passphrase)?"\n":"");
#ifndef G_PLATFORM_WIN32
	if (mlock(passphrase, strlen(passphrase)) == -1)
		debug_print("couldn't lock passphrase\n");
	if (mlock(passphrase_second, strlen(passphrase_second)) == -1)
		debug_print("couldn't lock passphrase2\n");
#endif
	g_free(tmp);
	g_free(email);
	g_free(name);
	g_free(passphrase_second);
	g_free(passphrase);
	
	err = gpgme_new (&ctx);
	if (err) {
		alertpanel_error(_("Couldn't generate a new key pair: %s"),
				 gpgme_strerror(err));
		g_free(key_parms);
		return;
	}
	

	window = label_window_create(_("Generating your new key pair... Please move the mouse "
			      "around to help generate entropy..."));

	err = gpgme_op_genkey(ctx, key_parms, NULL, NULL);
	g_free(key_parms);

	label_window_destroy(window);

	if (err) {
		alertpanel_error(_("Couldn't generate a new key pair: %s"), gpgme_strerror(err));
		gpgme_release(ctx);
		return;
	}
	key = gpgme_op_genkey_result(ctx);
	if (key == NULL) {
		alertpanel_error(_("Couldn't generate a new key pair: unknown error"));
		gpgme_release(ctx);
		return;
	} else {
		gchar *buf = g_strdup_printf(_("Your new key pair has been generated. "
				    "Its fingerprint is:\n%s\n\nDo you want to export it "
				    "to a keyserver?"),
				    key->fpr ? key->fpr:"null");
		AlertValue val = alertpanel(_("Key generated"), buf,
				  GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL);
		g_free(buf);
		if (val == G_ALERTALTERNATE) {
#ifndef G_OS_WIN32
			gchar *cmd = g_strdup_printf("gpg --no-tty --send-keys %s", key->fpr);
			int res = 0;
			pid_t pid = 0;
			pid = fork();
			if (pid == -1) {
				res = -1;
			} else if (pid == 0) {
				/* son */
				res = system(cmd);
				res = WEXITSTATUS(res);
				_exit(res);
			} else {
				int status = 0;
				time_t start_wait = time(NULL);
				res = -1;
				do {
					if (waitpid(pid, &status, WNOHANG) == 0 || !WIFEXITED(status)) {
						usleep(200000);
					} else {
						res = WEXITSTATUS(status);
						break;
					}
					if (time(NULL) - start_wait > 5) {
						debug_print("SIGTERM'ing gpg\n");
						kill(pid, SIGTERM);
					}
					if (time(NULL) - start_wait > 6) {
						debug_print("SIGKILL'ing gpg\n");
						kill(pid, SIGKILL);
						break;
					}
				} while(1);
			}
			if (res == 0) {
				alertpanel_notice(_("Key exported."));
			} else {
				alertpanel_error(_("Couldn't export key."));
			}
			g_free(cmd);
#else
			alertpanel_error(_("Key export isn't implemented in Windows."));
#endif
		}
	}
	prefs_gpg_get_config()->gpg_ask_create_key = FALSE;
	prefs_gpg_save_config();
	gpgme_release(ctx);
}
static void received_event_modify_request(gint fd)
{
	gchar buf[BUFFSIZE];
	gchar *new_vevent = NULL;

	if (fd_gets(fd, buf, sizeof(buf)) != -1) {
		gchar *id;
		id = g_strchomp(buf);
		g_print("id to change: '%s'\n",id);

		if(vcal_event_exists(id)) {
			AlertValue val;
			val = G_ALERTALTERNATE;
			if(opensync_config.event_ask_modify) {
				gchar *msg;
				msg = g_strdup_printf(_("Really modify event ID '%s'?"), id);
				val = alertpanel(_("OpenSync plugin"),msg,
												 GTK_STOCK_CANCEL,GTK_STOCK_EDIT,NULL);
				g_free(msg);
			}
			if((!opensync_config.event_ask_modify) || (val != G_ALERTDEFAULT)) {
				gchar *vevent = g_strdup("");
				gchar *tmp;
				gboolean done = FALSE;

				while(!done) {
					if(fd_gets(answer_sock, buf, sizeof(buf)) == -1) {
						g_print("error receiving event to modify\n");
						break;
					}
					if(g_str_has_prefix(buf,":done:"))
						done = TRUE;
					else {
						tmp = vevent;
						vevent = g_strconcat(tmp,buf,NULL);
						g_free(tmp);
					}
				}
				g_print("Modification to: '%s'\n", vevent);
				if((new_vevent = vcal_update_event(vevent)) != NULL)
					g_print("event updated successfully\n");
				else
					g_print("could not update event\n");
				g_free(vevent);
			}
			else {
				g_print("Error: User refused to modify event ID '%s'\n", id);
			}
		}
		else
			g_printf("warning: tried to modify non-existent event\n");

		if(new_vevent) {
			gchar *msg;
			sock_send(fd, ":start_event:\n");
			msg = g_strdup_printf("%s\n", new_vevent);
			g_free(new_vevent);
			sock_send(fd, msg);
			g_free(msg);
			sock_send(fd, ":end_event:\n");
		}
		else
			sock_send(fd, ":failure:\n");			
	}
}
static void received_contact_add_request(gint fd)
{
	gchar *vcard;
	gchar *msg;
	gboolean add_successful;
	ItemPerson *person;

	add_successful = FALSE;
	vcard = get_next_contact();

	if (vcard) {
		AlertValue val;
		val = G_ALERTALTERNATE;
		if (opensync_config.contact_ask_add) {
			msg = g_strdup_printf(_("Really add contact:\n%s?"),vcard);
			val = alertpanel(_("OpenSync plugin"),msg,
											 GTK_STOCK_CANCEL,GTK_STOCK_ADD,NULL);
			g_free(msg);
		}
		if (!opensync_config.contact_ask_add || (val != G_ALERTDEFAULT)) {
			gchar *path = NULL;
			AddressDataSource *book = NULL;
			ItemFolder *folder = NULL;
			AddressBookFile *abf = NULL;

			if(opensync_config.addrbook_choice == OPENSYNC_ADDRESS_BOOK_INDIVIDUAL)
				path = addressbook_folder_selection(NULL);
			if(!path)
				path = g_strdup(opensync_config.addrbook_folderpath);

			if (addressbook_peek_folder_exists(path, &book, &folder) && book) {
				abf = book->rawDataSource;
				person = addrbook_add_contact(abf, folder, "", "", "");
				person->status = ADD_ENTRY;
				update_ItemPerson_from_vcard(abf, person, vcard);
				add_successful = TRUE;
			}
			else
				g_warning("addressbook folder not found '%s'\n", path);
			g_free(path);
		}
		else {
			g_print("Error: User refused to add contact '%s'\n", vcard);
		}
	}
	else {
		g_print("Error: Not able to get the contact to add\n");
	}
	if(add_successful) {
		gchar *return_vcard;
		return_vcard = vcard_get_from_ItemPerson(person);
		
	  sock_send(fd, ":start_contact:\n");
	  msg = g_strdup_printf("%s\n", return_vcard);
		g_free(return_vcard);
	  sock_send(fd, msg);
	  g_free(msg);
	  sock_send(fd, ":end_contact:\n");	  
	}
	else {
	  sock_send(fd, ":failure:\n");
	}
	g_free(vcard);
}
static void received_contact_modify_request(gint fd)
{
	gchar buf[BUFFSIZE];
	gchar *return_vcard = NULL;

	if (fd_gets(fd, buf, sizeof(buf)) != -1) {
		gchar *id;
		ContactHashVal *hash_val;
		id = g_strchomp(buf);
		g_print("id to change: '%s'\n",id);
		hash_val = g_hash_table_lookup(contact_hash, id);
		if(hash_val) {
			AlertValue val;
			val = G_ALERTALTERNATE;
			if(opensync_config.contact_ask_modify) {
				gchar *msg;
				msg = g_strdup_printf(_("Really modify contact for '%s'?"),
															ADDRITEM_NAME(hash_val->person));
				val = alertpanel(_("OpenSync plugin"),msg,
												 GTK_STOCK_CANCEL,GTK_STOCK_EDIT,NULL);
				g_free(msg);
			}
			if((!opensync_config.contact_ask_modify) || (val != G_ALERTDEFAULT)) {
				gchar *vcard = g_strdup("");
				gchar *tmp;
				gboolean done = FALSE;
				AddressBookFile *abf;
				
				while(!done) {
					if(fd_gets(answer_sock, buf, sizeof(buf)) == -1) {
						g_print("error receiving contact to modify\n");
						break;
					}
					g_print("buf: %s\n",buf);
					if(g_str_has_prefix(buf,":done:"))
						done = TRUE;
					else {
						tmp = vcard;
						vcard = g_strconcat(tmp,buf,NULL);
						g_free(tmp);
					}
				}
				abf = hash_val->ds->rawDataSource;
				g_print("Modification to: '%s'\n",vcard);
				update_ItemPerson_from_vcard(abf, hash_val->person, vcard);
				g_free(vcard);
				return_vcard = vcard_get_from_ItemPerson(hash_val->person);
			}
			else {
				g_print("Error: User refused to modify contact '%s'\n",
								ADDRITEM_NAME(hash_val->person));
			}
		}
		else
			g_printf("warning: tried to modify non-existent contact\n");

		if(return_vcard) {
			send_
			gchar *msg;
			sock_send(fd, ":start_contact:\n");
			msg = g_strdup_printf("%s\n", return_vcard);
			g_free(return_vcard);
			sock_send(fd, msg);
			g_free(msg);
			sock_send(fd, ":end_contact:\n");	  
		}
		else
			sock_send(fd, ":failure:\n");
	}
}
Exemple #16
0
static void pgpview_show_mime_part(TextView *textview, MimeInfo *partinfo)
{
	GtkTextView *text;
	GtkTextBuffer *buffer;
	GtkTextIter iter;
	gpgme_data_t sigdata = NULL;
	gpgme_verify_result_t sigstatus = NULL;
	gpgme_ctx_t ctx = NULL;
	gpgme_key_t key = NULL;
	gpgme_signature_t sig = NULL;
	gpgme_error_t err = 0;
	gboolean imported = FALSE;

	if (!partinfo) return;
	
	textview_set_font(textview, NULL);
	textview_clear(textview);

	text = GTK_TEXT_VIEW(textview->text);
	buffer = gtk_text_view_get_buffer(text);
	gtk_text_buffer_get_start_iter(buffer, &iter);

	err = gpgme_new (&ctx);
	if (err) {
		debug_print("err : %s\n", gpgme_strerror(err));
		textview_show_mime_part(textview, partinfo);
		return;
	}
	
	sigdata = sgpgme_data_from_mimeinfo(partinfo);
	if (!sigdata) {
		g_warning("no sigdata");
		textview_show_mime_part(textview, partinfo);
		return;
	}

	/* Here we do not care about what data we attempt to verify with the
	 * signature, or about result of the verification - all we care about
	 * is that we find out ID of the key used to make this signature. */
	sigstatus = sgpgme_verify_signature(ctx, sigdata, NULL, sigdata);
	if (!sigstatus || sigstatus == GINT_TO_POINTER(-GPG_ERR_SYSTEM_ERROR)) {
		g_warning("no sigstatus");
		textview_show_mime_part(textview, partinfo);
		return;
	}
	sig = sigstatus->signatures;
	if (!sig) {
		g_warning("no sig");
		textview_show_mime_part(textview, partinfo);
		return;
	}
	gpgme_get_key(ctx, sig->fpr, &key, 0);
	if (!key) {
		gchar *gpgbin = get_gpg_executable_name();
		gchar *cmd = g_strdup_printf("\"%s\" --batch --no-tty --recv-keys %s",
				(gpgbin ? gpgbin : "gpg"), sig->fpr);
		AlertValue val = G_ALERTDEFAULT;
		if (!prefs_common_get_prefs()->work_offline) {
			val = alertpanel(_("Key import"),
				_("This key is not in your keyring. Do you want "
				  "Claws Mail to try and import it from a "
				  "keyserver?"),
				  GTK_STOCK_NO, GTK_STOCK_YES, NULL, ALERTFOCUS_SECOND);
			GTK_EVENTS_FLUSH();
		}
		if (val == G_ALERTDEFAULT) {
			TEXTVIEW_INSERT(_("\n  Key ID "));
			TEXTVIEW_INSERT(sig->fpr);
			TEXTVIEW_INSERT(":\n\n");
			TEXTVIEW_INSERT(_("   This key is not in your keyring.\n"));
			TEXTVIEW_INSERT(_("   It should be possible to import it "));
			if (prefs_common_get_prefs()->work_offline)
				TEXTVIEW_INSERT(_("when working online,\n   or "));
			TEXTVIEW_INSERT(_("with the following command: \n\n     "));
			TEXTVIEW_INSERT(cmd);
		} else {
			TEXTVIEW_INSERT(_("\n  Importing key ID "));
			TEXTVIEW_INSERT(sig->fpr);
			TEXTVIEW_INSERT(":\n\n");

			main_window_cursor_wait(mainwindow_get_mainwindow());
			textview_cursor_wait(textview);
			GTK_EVENTS_FLUSH();

#ifndef G_OS_WIN32
			int res = 0;
			pid_t pid = 0;

			pid = fork();
			if (pid == -1) {
				res = -1;
			} else if (pid == 0) {
				/* son */
				gchar **argv;
				argv = strsplit_with_quote(cmd, " ", 0);
				res = execvp(argv[0], argv);
				perror("execvp");
				exit(255);
			} else {
				int status = 0;
				time_t start_wait = time(NULL);
				res = -1;
				do {
					if (waitpid(pid, &status, WNOHANG) == 0 || !WIFEXITED(status)) {
						usleep(200000);
					} else {
						res = WEXITSTATUS(status);
						break;
					}
					if (time(NULL) - start_wait > 9) {
						debug_print("SIGTERM'ing gpg %d\n", pid);
						kill(pid, SIGTERM);
					}
					if (time(NULL) - start_wait > 10) {
						debug_print("SIGKILL'ing gpg %d\n", pid);
						kill(pid, SIGKILL);
						break;
					}
				} while(1);
			}
			debug_print("res %d\n", res);
			if (res == 0)
				imported = TRUE;
#else
			/* We need to call gpg in a separate thread, so that waiting for
			 * it to finish does not block the UI. */
			pthread_t pt;
			struct _ImportCtx *ctx = malloc(sizeof(struct _ImportCtx));

			ctx->done = FALSE;
			ctx->exitcode = STILL_ACTIVE;
			ctx->cmd = cmd;

			if (pthread_create(&pt, NULL,
						_import_threaded, (void *)ctx) != 0) {
				debug_print("Couldn't create thread, continuing unthreaded.\n");
				_import_threaded(ctx);
			} else {
				debug_print("Thread created, waiting for it to finish...\n");
				while (!ctx->done)
					claws_do_idle();
			}

			debug_print("Thread finished.\n");
			pthread_join(pt, NULL);

			if (ctx->exitcode == 0) {
				imported = TRUE;
			}
			g_free(ctx);
#endif
			main_window_cursor_normal(mainwindow_get_mainwindow());
			textview_cursor_normal(textview);
			if (imported) {
				TEXTVIEW_INSERT(_("   This key has been imported to your keyring.\n"));
			} else {
				TEXTVIEW_INSERT(_("   This key couldn't be imported to your keyring.\n"));
				TEXTVIEW_INSERT(_("   Key servers are sometimes slow.\n"));
				TEXTVIEW_INSERT(_("   You can try to import it manually with the command:\n\n     "));
				TEXTVIEW_INSERT(cmd);
			}
		}
		g_free(cmd);
		return;
	} else {
		TEXTVIEW_INSERT(_("\n  Key ID "));

#if defined GPGME_VERSION_NUMBER && GPGME_VERSION_NUMBER >= 0x010700
		TEXTVIEW_INSERT(key->fpr);
#else
		TEXTVIEW_INSERT(sig->fpr);
#endif

		TEXTVIEW_INSERT(":\n\n");
		TEXTVIEW_INSERT(_("   This key is in your keyring.\n"));
	}
	gpgme_data_release(sigdata);
	gpgme_release(ctx);
	textview_show_icon(textview, GTK_STOCK_DIALOG_AUTHENTICATION);
}