#include "advsearch.h"
#include "avatars.h"
#include "passwordstore.h"
-#include "safe_fclose.h"
+#include "file-utils.h"
#ifdef HAVE_LIBETPAN
#include "imap-thread.h"
static gint lock_socket = -1;
static gint lock_socket_tag = 0;
+#ifdef G_OS_UNIX
static gchar *x_display = NULL;
+#endif
typedef enum
{
ONLINE_MODE_DONT_CHANGE,
{
gboolean autochk = GPOINTER_TO_INT(data);
- inc_all_account_mail(static_mainwindow, autochk,
+ if (!sc_starting) {
+ inc_all_account_mail(static_mainwindow, autochk, FALSE,
prefs_common.newmail_notify_manu);
- if (sc_starting) {
+ } else {
+ inc_all_account_mail(static_mainwindow, FALSE,
+ prefs_common.chk_on_startup,
+ prefs_common.newmail_notify_manu);
sc_starting = FALSE;
main_window_set_menu_sensitive(static_mainwindow);
toolbar_main_set_sensitive(static_mainwindow);
gchar buf[BUFFSIZE];
gboolean err = FALSE;
- oldfp = g_fopen(old_rc, "r");
+ oldfp = claws_fopen(old_rc, "r");
if (!oldfp)
return -1;
- newfp = g_fopen(new_rc, "w");
+ newfp = claws_fopen(new_rc, "w");
if (!newfp) {
- fclose(oldfp);
+ claws_fclose(oldfp);
return -1;
}
old_plugin_path = g_strdup(new_plugin_path);
}
debug_print("replacing %s with %s\n", old_plugin_path, new_plugin_path);
- while (fgets(buf, sizeof(buf), oldfp)) {
+ while (claws_fgets(buf, sizeof(buf), oldfp)) {
if (strncmp(buf, old_plugin_path, strlen(old_plugin_path))) {
- err |= (fputs(buf, newfp) == EOF);
+ err |= (claws_fputs(buf, newfp) == EOF);
} else {
debug_print("->replacing %s\n", buf);
debug_print(" with %s%s\n", new_plugin_path, buf+strlen(old_plugin_path));
- err |= (fputs(new_plugin_path, newfp) == EOF);
- err |= (fputs(buf+strlen(old_plugin_path), newfp) == EOF);
+ err |= (claws_fputs(new_plugin_path, newfp) == EOF);
+ err |= (claws_fputs(buf+strlen(old_plugin_path), newfp) == EOF);
}
}
g_free(plugin_path);
g_free(new_plugin_path);
g_free(old_plugin_path);
- fclose(oldfp);
- if (safe_fclose(newfp) == EOF)
+ claws_fclose(oldfp);
+ if (claws_safe_fclose(newfp) == EOF)
err = TRUE;
return (err ? -1:0);
NULL, &client_id,
256, error_string_ret);
+ /* From https://www.x.org/releases/X11R7.7/doc/libSM/SMlib.txt:
+ * If SmcOpenConnection succeeds, it returns an opaque connection
+ * pointer of type SmcConn and the client_id_ret argument contains
+ * the client ID to be used for this session. The client_id_ret
+ * should be freed with a call to free when no longer needed. On
+ * failure, SmcOpenConnection returns NULL, and the reason for
+ * failure is returned in error_string_ret. */
+ if (mainwin->smc_conn != NULL)
+ g_free(client_id);
+
if (error_string_ret[0] || mainwin->smc_conn == NULL)
g_warning ("While connecting to session manager: %s.",
error_string_ret);
static void win32_open_log(void)
{
- gchar *logfile = g_strconcat(g_get_tmp_dir(), G_DIR_SEPARATOR_S, "claws-win32.log", NULL);
- gchar *oldlogfile = g_strconcat(g_get_tmp_dir(), G_DIR_SEPARATOR_S, "claws-win32.log.bak", NULL);
+ gchar *logfile = win32_debug_log_path();
+ gchar *oldlogfile = g_strconcat(logfile, ".bak", NULL);
if (is_file_exist(logfile)) {
if (rename_force(logfile, oldlogfile) < 0)
FILE_OP_ERROR(logfile, "rename");
}
- win32_debug_fp = g_fopen(logfile, "w");
+ win32_debug_fp = claws_fopen(logfile, "w");
g_free(logfile);
g_free(oldlogfile);
if (win32_debug_fp)
g_log_remove_handler("", win32_log_handler_app_id);
g_log_remove_handler("GLib", win32_log_handler_glib_id);
g_log_remove_handler("Gtk", win32_log_handler_gtk_id);
- fclose(win32_debug_fp);
+ claws_fclose(win32_debug_fp);
win32_debug_fp=NULL;
}
}
#ifdef CRASH_DIALOG
if (cmd.crash) {
-#if !GTK_CHECK_VERSION(3, 0, 0)
gtk_set_locale();
-#endif
gtk_init(&argc, &argv);
crash_main(cmd.crash_params);
#ifdef G_OS_WIN32
reset_statistics();
-#if !GTK_CHECK_VERSION(3, 0, 0)
gtk_set_locale();
-#endif
gtk_init(&argc, &argv);
#ifdef G_OS_WIN32
}
#endif
-#if !GTK_CHECK_VERSION(3, 0, 0)
gtk_widget_set_default_colormap(
gdk_screen_get_system_colormap(
gdk_screen_get_default()));
-#endif
gtkut_create_ui_manager();
folder_item_update_freeze();
}
/* make the crash-indicator file */
- str_write_to_file("foo", get_crashfile_name());
+ if (str_write_to_file("foo", get_crashfile_name(), FALSE) < 0) {
+ g_warning("Can't create the crash-indicator file.");
+ }
inc_autocheck_timer_init(mainwin);
if (prefs_common.last_opened_folder != NULL)
g_free(prefs_common.last_opened_folder);
prefs_common.last_opened_folder =
+ !prefs_common.goto_last_folder_on_startup ? NULL :
folder_item_get_identifier(item);
}
if (isstdin)
fp = stdin;
else {
- fp = g_fopen(fn, "r");
+ fp = claws_fopen(fn, "r");
if (!fp)
G_PRINT_EXIT(_("Cannot open filename for reading\n"));
}
- while (fgets(fb, sizeof(fb), fp)) {
+ while (claws_fgets(fb, sizeof(fb), fp)) {
gchar *tmp;
strretchomp(fb);
if (*fb == '\0')
g_string_append(body, to);
g_free(to);
g_string_append(body, "?body=");
- while (fgets(fb, sizeof(fb), fp)) {
+ while (claws_fgets(fb, sizeof(fb), fp)) {
g_string_append_uri_escaped(body, fb, NULL, TRUE);
}
if (!isstdin)
- fclose(fp);
+ claws_fclose(fp);
/* append the remaining headers */
g_string_append(body, headers->str);
g_string_free(headers, TRUE);
" use - as file name for reading from standard input;\n"
" content format: headers first (To: required) until an\n"
" empty line, then mail body until end of file."));
- g_print("%s\n", _(" --subscribe [uri] subscribe to the given URI if possible"));
+ g_print("%s\n", _(" --subscribe uri subscribe to the given URI if possible"));
g_print("%s\n", _(" --attach file1 [file2]...\n"
" open composition window with specified files\n"
" attached"));
g_print("%s\n", _(" --version -v output version information and exit"));
g_print("%s\n", _(" --version-full -V output version and built-in features information and exit"));
g_print("%s\n", _(" --config-dir output configuration directory"));
- g_print("%s\n", _(" --alternate-config-dir [dir]\n"
+ g_print("%s\n", _(" --alternate-config-dir directory\n"
" use specified configuration directory"));
g_print("%s\n", _(" --geometry -geometry WxH+X+Y\n"
" set geometry for main window"));
} else if (is_dir_exist(argv[i]) || is_file_exist(argv[i])) {
cmd.target = argv[i];
} else {
- g_print(_("Unknown option\n"));
+ g_print(_("Unknown option. Try -h or --help for usage.\n"));
exit(1);
}
}
} else if (cmd.send) {
fd_write_all(uxsock, "send\n", 5);
} else if (cmd.online_mode == ONLINE_MODE_ONLINE) {
- fd_write(uxsock, "online\n", 6);
+ fd_write(uxsock, "online\n", 7);
} else if (cmd.online_mode == ONLINE_MODE_OFFLINE) {
- fd_write(uxsock, "offline\n", 7);
+ fd_write(uxsock, "offline\n", 8);
} else if (cmd.debug) {
- fd_write(uxsock, "debug\n", 7);
+ fd_write(uxsock, "debug\n", 6);
} else if (cmd.status || cmd.status_full) {
gchar buf[BUFFSIZE];
gint i;
fd_gets(uxsock, buf, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
if (!strncmp(buf, ".\n", 2)) break;
- fputs(buf, stdout);
+ if (claws_fputs(buf, stdout) == EOF) {
+ g_warning("writing to stdout failed.");
+ break;
+ }
}
} else if (cmd.exit) {
fd_write_all(uxsock, "exit\n", 5);
fd_gets(uxsock, buf, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
if (!strncmp(buf, ".\n", 2)) break;
- fputs(buf, stdout);
+ if (claws_fputs(buf, stdout) == EOF) {
+ g_warning("writing to stdout failed.");
+ break;
+ }
}
} else if (cmd.reset_statistics) {
fd_write(uxsock, "reset_statistics\n", 17);
fd_gets(uxsock, buf, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
if (!strncmp(buf, ".\n", 2)) break;
- fputs(buf, stdout);
+ if (claws_fputs(buf, stdout) == EOF) {
+ g_warning("writing to stdout failed.");
+ break;
+ }
}
} else {
-#ifndef G_OS_WIN32
+#ifdef G_OS_UNIX
gchar buf[BUFSIZ];
fd_write_all(uxsock, "get_display\n", 12);
memset(buf, 0, sizeof(buf));
fd_gets(uxsock, buf, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
- if (strcmp2(buf, x_display)) {
+ if (g_strcmp0(buf, x_display)) {
g_print("Claws Mail is already running on display %s.\n",
buf);
} else {
if (!strncmp(buf, "popup", 5)) {
main_window_popup(mainwin);
+#ifdef G_OS_UNIX
} else if (!strncmp(buf, "get_display", 11)) {
fd_write_all(sock, x_display, strlen(x_display));
+#endif
} else if (!strncmp(buf, "receive_all", 11)) {
- inc_all_account_mail(mainwin, FALSE,
+ inc_all_account_mail(mainwin, FALSE, FALSE,
prefs_common.newmail_notify_manu);
} else if (!strncmp(buf, "receive", 7)) {
inc_mail(mainwin, prefs_common.newmail_notify_manu);
while (fd_gets(sock, buf, sizeof(buf) - 1) > 0) {
buf[sizeof(buf) - 1] = '\0';
strretchomp(buf);
- if (!strcmp2(buf, "."))
+ if (!g_strcmp0(buf, "."))
break;
ainfo = g_new0(AttachInfo, 1);