talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 86efe37f90a96dd86666bfb4d5d95b8cbdfee096
parent 4b7ba8fc844b29f5ab39333b96089c1d176eaf37
Author: wwp <subscript@free.fr>
Date:   Thu, 16 Sep 2021 10:07:08 +0200

Merge branch 'gtk3' of ssh+git://git.claws-mail.org/home/git/claws into gtk3

Diffstat:
Msrc/common/Makefile.am | 6++----
Msrc/common/log.c | 4----
Msrc/common/socket.c | 1-
Msrc/common/timing.h | 2+-
Msrc/common/utils.c | 1-
Dsrc/common/w32_account.c | 151------------------------------------------------------------------------------
Msrc/common/w32_reg.c | 225++++++++++++++++++++++++++++++++-----------------------------------------------
Asrc/common/w32_reg.h | 40++++++++++++++++++++++++++++++++++++++++
Dsrc/common/w32_signal.c | 28----------------------------
Dsrc/common/w32_stat.c | 30------------------------------
Dsrc/common/w32_stdlib.c | 38--------------------------------------
Dsrc/common/w32_string.c | 53-----------------------------------------------------
Dsrc/common/w32_time.c | 37-------------------------------------
Dsrc/common/w32_unistd.c | 45---------------------------------------------
Dsrc/common/w32_wait.c | 28----------------------------
Dsrc/common/w32lib.h | 224-------------------------------------------------------------------------------
Msrc/exporthtml.c | 4----
Msrc/folder.c | 3---
Msrc/mainwindow.c | 130+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
Msrc/mbox.c | 4----
Msrc/msgcache.c | 1-
Msrc/plugins/pgpcore/passphrase.c | 2+-
Msrc/prefs_summaries.c | 4----
Msrc/procheader.c | 4----
Msrc/procmime.c | 15++++++++++++---
Msrc/recv.c | 4+---
26 files changed, 228 insertions(+), 856 deletions(-)

diff --git a/src/common/Makefile.am b/src/common/Makefile.am @@ -14,10 +14,8 @@ DESKTOPFILEPATH=$(datadir)/applications/claws-mail.desktop noinst_LTLIBRARIES = libclawscommon.la if OS_WIN32 -arch_sources = w32_reg.c w32_signal.c w32_stat.c \ - w32_stdlib.c w32_string.c w32_time.c \ - w32_unistd.c w32_wait.c w32_account.c -arch_headers = w32lib.h +arch_sources = w32_reg.c +arch_headers = w32_reg.h else arch_files = arch_header = diff --git a/src/common/log.c b/src/common/log.c @@ -24,10 +24,6 @@ #include "defs.h" -#ifdef G_OS_WIN32 -# include <w32lib.h> -#endif - #include <glib.h> #include <glib/gi18n.h> diff --git a/src/common/socket.c b/src/common/socket.c @@ -37,7 +37,6 @@ # ifndef EINPROGRESS # define EINPROGRESS WSAEINPROGRESS # endif -# include "w32lib.h" #else # if HAVE_SYS_WAIT_H # include <sys/wait.h> diff --git a/src/common/timing.h b/src/common/timing.h @@ -53,7 +53,7 @@ #ifdef G_OS_WIN32 -#include <w32lib.h> +#include <windows.h> /* no {} by purpose */ #define START_TIMING(str) \ diff --git a/src/common/utils.c b/src/common/utils.c @@ -80,7 +80,6 @@ #ifdef G_OS_WIN32 # include <direct.h> # include <io.h> -# include <w32lib.h> #endif #include "utils.h" diff --git a/src/common/w32_account.c b/src/common/w32_account.c @@ -1,151 +0,0 @@ -/* w32_account.c - Account related W32 functions. - Copyright (C) 2007-2009 g10 Code GmbH - Copyright (C) 1999-2005 Nullsoft, Inc. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any - damages arising from the use of this software. - - Permission is granted to anyone to use this software for any - purpose, including commercial applications, and to alter it and - redistribute it freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. - - =======[ wk 2007-05-21 ]==== - The code for get_group_name has been taken from NSIS 2.05, module - UserInfo.c. NSIS bears the above license and along with the - notice: - This license applies to everything in the NSIS package, except where - otherwise noted. - Thus we make this module available under the same license - note, - that this lincese is fully compatibe with the GNU GPL 2.0. -*/ - - - - -#include <stdlib.h> -#include <string.h> -#include <windows.h> -#include <sddl.h> // for ConvertSidToStringSid() - -#include "w32lib.h" -#include "utils.h" - -#ifndef DIM -#define DIM(v) (sizeof(v)/sizeof((v)[0])) -#endif - - -/* Return a malloced name of our user group. */ -static char * -get_group_name (void) -{ - HANDLE hThread; - TOKEN_GROUPS *ptg = NULL; - DWORD cbTokenGroups; - DWORD i, j; - SID_IDENTIFIER_AUTHORITY SystemSidAuthority = { SECURITY_NT_AUTHORITY }; - char *group; - struct - { - DWORD auth_id; - char *name; - } groups[] = - { - /* Every user belongs to the users group, hence - users comes before guests */ - {DOMAIN_ALIAS_RID_USERS, "User"}, - {DOMAIN_ALIAS_RID_GUESTS, "Guest"}, - {DOMAIN_ALIAS_RID_POWER_USERS, "Power"}, - {DOMAIN_ALIAS_RID_ADMINS, "Admin"} - }; - - - group = NULL; - if (GetVersion() & 0x80000000) - { - /* This is not NT; thus we are always Admin. */ - group = "Admin"; - } - else if (OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &hThread) - || OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hThread)) - { - /* With the token for the current thread or process in hand we - query the size of the associated group information. Note - that we expect an error because buffer has been passed as - NULL. cbTokenGroups will then tell use the required size. */ - if (!GetTokenInformation (hThread, TokenGroups, NULL, 0, &cbTokenGroups) - && GetLastError () == ERROR_INSUFFICIENT_BUFFER) - { - ptg = GlobalAlloc (GPTR, cbTokenGroups); - if (ptg) - { - if (GetTokenInformation ( hThread, TokenGroups, ptg, - cbTokenGroups, &cbTokenGroups)) - { - - /* Now iterate through the list of groups for this - access token looking for a match against the SID - we created above. */ - for (i = 0; i < DIM (groups); i++) - { - PSID psid = 0; - - AllocateAndInitializeSid (&SystemSidAuthority, - 2, - SECURITY_BUILTIN_DOMAIN_RID, - groups[i].auth_id, - 0, 0, 0, 0, 0, 0, - &psid); - if (!psid) - continue; - for (j = 0; j < ptg->GroupCount; j++) - if (EqualSid(ptg->Groups[j].Sid, psid)) - group = groups[i].name; - FreeSid(psid); - } - } - - GlobalFree(ptg); - } - } - - CloseHandle(hThread); - } - - return group? strdup (group):NULL; -} - - -/* Return true if we are an administrator. The chekc is done only - once so if the current user has been hadded to the Administrator - group the process needs to be rerstarted. */ -int -w32_is_administrator (void) -{ - static int got_it; - static int is_admin; - - if (!got_it) - { - char *name = get_group_name (); - - if (name && !strcmp (name, "Admin")) - is_admin = 1; - got_it = 1; - free (name); - } - - return is_admin; -} diff --git a/src/common/w32_reg.c b/src/common/w32_reg.c @@ -1,172 +1,127 @@ -/* w32_reg.c - Posix emulation layer for Sylpheed (Claws) +/* + * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client + * Copyright (C) 1999-2021 the Claws Mail team and Hiroyuki Yamamoto * - * This file is part of w32lib. - * - * w32lib is free software; you can redistribute it and/or modify + * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * w32lib is distributed in the hope that it will be useful, + * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * For more information and a list of changes, see w32lib.h */ -#include <windows.h> +#include "w32_reg.h" #include "utils.h" -#include "w32lib.h" - -static HKEY get_root_key_from_str(char *parent) -{ - HKEY rootKey = NULL; - if (!parent || !strlen(parent)) - rootKey = HKEY_CURRENT_USER ; - else if (!strcmp(parent, "HKCR") || !strcmp(parent,"HKEY_CLASSES_ROOT")) - rootKey = HKEY_CLASSES_ROOT ; - else if (!strcmp(parent, "HKCU") || !strcmp(parent,"HKEY_CURRENT_USER")) - rootKey = HKEY_CURRENT_USER ; - else if (!strcmp(parent, "HKLM") || !strcmp(parent,"HKEY_LOCAL_MACHINE")) - rootKey = HKEY_LOCAL_MACHINE ; - else if (!strcmp(parent, "HKU") || !strcmp(parent,"HKEY_USERS")) - rootKey = HKEY_USERS ; - else if (!strcmp(parent, "HKCC") || !strcmp(parent,"HKEY_CURRENT_CONFIG")) - rootKey = HKEY_CURRENT_CONFIG ; - return rootKey; -} - -int write_w32_registry_string( char *parent, char *section, char *value, char *data ) +gboolean reg_set_value(HKEY root, + const gchar *subkey, + const gchar *value, + DWORD type, + const BYTE *data, + DWORD data_size) { - HKEY hKey, rootKey; - int ret; + DWORD ret; + HKEY key; + gchar *tmp; - rootKey = get_root_key_from_str(parent); - ret = RegCreateKeyEx(rootKey, section, 0, NULL, - REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); + ret = RegCreateKeyEx(root, subkey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL); if (ret != ERROR_SUCCESS) { - debug_print("can't write key %s\\%s: %d\n", parent, section, ret); - return -1; + tmp = g_win32_error_message(ret); + debug_print("RegCreateKeyEx %p \"%s\" had error: \"%s\"\n", root, subkey, tmp); + g_free(tmp); + return FALSE; } - ret = RegSetValueEx(hKey, value, 0, REG_SZ, (LPVOID)data, strlen(data)+1); + + ret = RegSetValueEx(key, value, 0, type, data, data_size); if (ret != ERROR_SUCCESS) { - RegCloseKey(hKey); - debug_print("can't write key %s\\%s: %d\n", parent, section, ret); - return -1; + tmp = g_win32_error_message(ret); + debug_print("RegSetValueEx %p \"%s\" had error: \"%s\"\n", root, subkey, tmp); + g_free(tmp); } - RegCloseKey(hKey); - return 0; + + RegCloseKey(key); + return (ret == ERROR_SUCCESS); } -int write_w32_registry_dword( char *parent, char *section, char *value, int data ) +gboolean write_w32_registry_string(HKEY root, + const gchar *subkey, + const gchar *value, + const gchar *data) { - HKEY hKey, rootKey; - int ret; - - rootKey = get_root_key_from_str(parent); - ret = RegCreateKeyEx(rootKey, section, 0, NULL, - REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); - if (ret != ERROR_SUCCESS) { - debug_print("can't write key %s\\%s: %d\n", parent, section, ret); - return -1; - } - ret = RegSetValueEx(hKey, value, 0, REG_DWORD, (LPBYTE)&data, sizeof(data)); - if (ret != ERROR_SUCCESS) { - RegCloseKey(hKey); - debug_print("can't write key %s\\%s: %d\n", parent, section, ret); - return -1; - } - RegCloseKey(hKey); - return 0; + return reg_set_value(root, subkey, value, REG_SZ, (BYTE *)data, strlen(data) + 1); } -char *read_w32_registry_string( char *parent, char *section, char *key ) +gboolean write_w32_registry_dword(HKEY root, + const gchar *subkey, + const gchar *value, + DWORD data) { - HKEY hKey, rootKey; - char *str; - int ret; - - char buf[ MAX_PATH ]; - DWORD bufsiz = sizeof( buf ); - - rootKey = get_root_key_from_str(parent); - - if (!rootKey) - return NULL; - - str = NULL; - ret = RegOpenKeyEx( rootKey, section, 0, KEY_READ, &hKey ); - if ( ERROR_SUCCESS == ret ){ - ret = RegQueryValueEx( hKey, key, 0, NULL, - (LPBYTE)buf, &bufsiz ); - if ( ERROR_SUCCESS == ret ){ - str = strdup( buf ); - } - RegCloseKey( hKey ); - } - return str; + return reg_set_value(root, subkey, value, REG_DWORD, (BYTE *)&data, sizeof(DWORD)); } -char *get_content_type_from_registry_with_ext( char *ext ) +gchar *read_w32_registry_string(HKEY root, const gchar *subkey, const gchar *value) { - HKEY hKey, parent; - int ret; - char buf[ MAX_PATH ]; - DWORD bufsiz; - char *section, *key, *value; - - if (ext == NULL) + HKEY hkey; + DWORD ret; + DWORD type; + BYTE *data; + DWORD data_size; + gchar *tmp; + + if (subkey == NULL) return NULL; - // parent : HKEY_CLASSES_ROOT - // section : ".txt" - parent = HKEY_CLASSES_ROOT; - section = malloc ( 1 + strlen (ext) + 1); - if (!section) - return NULL; - *section = '.'; - strcpy (section+1, ext); - - value = NULL; - while ( 1 ) { - ret = RegOpenKeyEx( parent, section, 0, KEY_READ, &hKey ); - if ( ERROR_SUCCESS != ret ) { - // If section is not found... - value = NULL; - break; - } - - // key : "Content Type" - key = "Content Type"; - bufsiz = sizeof( buf ); - ret = RegQueryValueEx( hKey, key, 0, NULL, (LPBYTE)buf, &bufsiz ); - if ( ERROR_SUCCESS == ret ) { - // If value is found! - RegCloseKey( hKey ); - value = strdup( buf ); - break; - } + ret = RegOpenKeyEx(root, subkey, 0, KEY_READ, &hkey); + if (ret != ERROR_SUCCESS) { + tmp = g_win32_error_message(ret); + debug_print("RegOpenKeyEx %p \"%s\" had error: \"%s\"\n", root, subkey, tmp); + g_free(tmp); + return NULL; + } - key = ""; - bufsiz = sizeof( buf ); - ret = RegQueryValueEx( hKey, key, 0, NULL, (LPBYTE)buf, &bufsiz ); - if ( ERROR_SUCCESS != ret ) { - RegCloseKey( hKey ); - value = NULL; - break; - } + // Get the needed buffer size + ret = RegQueryValueEx(hkey, value, 0, &type, NULL, &data_size); + if (ret != ERROR_SUCCESS) { + tmp = g_win32_error_message(ret); + debug_print("RegQueryValueEx %p \"%s\" \"%s\" had error: \"%s\" when getting buffer size\n", + root, subkey, value, tmp); + RegCloseKey(hkey); + g_free(tmp); + return NULL; + } else if (type != REG_SZ) { + debug_print("RegQueryValueEx %p \"%s\" \"%s\" returned type %lu instead of REG_SZ\n", + root, subkey, value, type); + RegCloseKey(hkey); + return NULL; + } else if (data_size == 0) { + debug_print("RegQueryValueEx %p \"%s\" \"%s\" returned data size 0\n", + root, subkey, value); + RegCloseKey(hkey); + return NULL; + } - RegCloseKey( hKey ); - free( section ); - section = strdup( buf ); - break; //XXX:tm-gtk2 + // The raw value is not necessarily NUL-terminated + data = g_malloc(data_size + 1); + + ret = RegQueryValueEx(hkey, value, 0, NULL, data, &data_size); + if (ret == ERROR_SUCCESS) { + data[data_size] = '\0'; + } else { + tmp = g_win32_error_message(ret); + debug_print("RegQueryValueEx %p \"%s\" \"%s\" had error: \"%s\"\n", + root, subkey, value, tmp); + RegCloseKey(hkey); + g_free(data); + g_free(tmp); + return NULL; } - free( section ); - return value; + RegCloseKey(hkey); + return (gchar *)data; } diff --git a/src/common/w32_reg.h b/src/common/w32_reg.h @@ -0,0 +1,40 @@ +/* + * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client + * Copyright (C) 1999-2021 the Claws Mail team and Hiroyuki Yamamoto + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __W32_REG_H__ +#define __W32_REG_H__ + +#include <windows.h> +#include <glib.h> + +gboolean write_w32_registry_string(HKEY root, + const gchar *subkey, + const gchar *value, + const gchar *data); + +gboolean write_w32_registry_dword(HKEY root, + const gchar *subkey, + const gchar *value, + DWORD data); + +// Caller should deallocate the return value with g_free() +gchar *read_w32_registry_string(HKEY root, + const gchar *subkey, + const gchar *value); + +#endif diff --git a/src/common/w32_signal.c b/src/common/w32_signal.c @@ -1,28 +0,0 @@ -/* w32_signal.c - Posix emulation layer for Sylpheed (Claws) - * - * This file is part of w32lib. - * - * w32lib is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * w32lib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * For more information and a list of changes, see w32lib.h - */ - -#include <stdlib.h> -#include <string.h> - -#include "w32lib.h" - -int kill( pid_t pid, int sig ){ - return -1; -} diff --git a/src/common/w32_stat.c b/src/common/w32_stat.c @@ -1,30 +0,0 @@ -/* w32_stat.c - Posix emulation layer for Sylpheed (Claws) - * - * This file is part of w32lib. - * - * w32lib is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * w32lib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * For more information and a list of changes, see w32lib.h - */ - -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> - -#include "w32lib.h" - -int lstat( const char *file_name, GStatBuf *buf ){ - return g_stat( file_name, buf ); -} - diff --git a/src/common/w32_stdlib.c b/src/common/w32_stdlib.c @@ -1,38 +0,0 @@ -/* w32_stdlib.c - Posix emulation layer for Sylpheed (Claws) - * - * This file is part of w32lib. - * - * w32lib is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * w32lib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * For more information and a list of changes, see w32lib.h - */ - -#include <stdlib.h> -#include <string.h> - -#include "w32lib.h" - -long int random( void ){ - return rand(); -} - -void srandom( unsigned int seed ){ - srand( seed ); -} - -#if MINGW64_VERSION < 200 -int truncate( const char *path, off_t length ){ - return -1; -} -#endif diff --git a/src/common/w32_string.c b/src/common/w32_string.c @@ -1,53 +0,0 @@ -/* w32_string.c - Posix emulation layer for Sylpheed (Claws) - * - * This file is part of w32lib. - * - * w32lib is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * w32lib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * For more information and a list of changes, see w32lib.h - */ - -#include <stdlib.h> -#include <string.h> -#include <ctype.h> - -#include "w32lib.h" - -#if MINGW64_VERSION < 200 -int strcasecmp( const char *s1, const char *s2 ){ - size_t len1, len2, len; - - len1 = strlen( s1 ); - len2 = strlen( s2 ); - len = ( len1 > len2 )? len1 : len2; - - return strncasecmp( s1, s2, len ); -} - -int strncasecmp( const char *s1, const char *s2, size_t n ){ - int c1; - int c2; - - while (n--) { - c1 = tolower(*(const unsigned char*)s1++); - c2 = tolower(*(const unsigned char*)s2++); - if (c1 != c2) - return c1 - c2; - else if (c1 == 0 && c2 == 0) - break; - } - - return 0; -} -#endif /* MINGW64_VERSION < 200 */ diff --git a/src/common/w32_time.c b/src/common/w32_time.c @@ -1,37 +0,0 @@ -/* w32_time.c - Posix emulation layer for Sylpheed (Claws) - * - * This file is part of w32lib. - * - * w32lib is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * w32lib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * For more information and a list of changes, see w32lib.h - */ - -#include <stdlib.h> -#include <string.h> -#include <sys/timeb.h> - -#include "w32lib.h" - -#if ! defined (__MINGW32__) || MINGW32_VERSION < 312 -# if MINGW64_VERSION < 200 -int gettimeofday( struct timeval *tv, struct timezone *tz ){ - struct _timeb tstruct; - _ftime( &tstruct ); - tv->tv_sec = tstruct.time ; - tv->tv_usec = tstruct.millitm; - return 1; -} -# endif -#endif diff --git a/src/common/w32_unistd.c b/src/common/w32_unistd.c @@ -1,45 +0,0 @@ -/* w32_unistd.c - Posix emulation layer for Sylpheed (Claws) - * - * This file is part of w32lib. - * - * w32lib is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * w32lib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * For more information and a list of changes, see w32lib.h - */ - -#include <stdlib.h> -#include <string.h> - -#include "w32lib.h" - -int setpgid( pid_t pid, pid_t pgid ){ - return -1; -} - -pid_t getppid( void ){ - return -1; -} - -pid_t fork( void ){ - return -1; -} - -unsigned int sleep( unsigned int seconds ){ - Sleep(seconds * 1000); - return 0; -} - -int usleep( unsigned long usec ){ - return sleep( 1 ); -} diff --git a/src/common/w32_wait.c b/src/common/w32_wait.c @@ -1,28 +0,0 @@ -/* w32_wait.c - Posix emulation layer for Sylpheed (Claws) - * - * This file is part of w32lib. - * - * w32lib is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * w32lib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * For more information and a list of changes, see w32lib.h - */ - -#include <stdlib.h> -#include <string.h> - -#include "w32lib.h" - -pid_t waitpid( pid_t pid, int *status, int options ){ - return -1; -} diff --git a/src/common/w32lib.h b/src/common/w32lib.h @@ -1,224 +0,0 @@ -/* w32lib.h - Posix emulation layer for Sylpheed (Claws) - * - * This file is part of w32lib. - * - * w32lib is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * w32lib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * The code has been taken from the package - * http://claws.sylpheed.org/win32/sylpheed/w32lib-dev-2004.2.3.0.zip - * on 2005-11-17 by Werner Koch <wk@gnupg.org>. There are no regular - * copyright notices but the file version.rc from the ZIP archive - * claims: - * - * #define FILEVER "2004.2.3.0\0" - * #define PRODVER "2004.2.3\0" - * - * [...] - * VALUE "FileDescription", "Posix emulation layer for Sylpheed (Claws)\0" - * VALUE "FileVersion", FILEVER - * VALUE "ProductVersion", PRODVER - * VALUE "LegalCopyright", "GPL\0" - * VALUE "CompanyName", "GNU / Free Software Foundation\0" - * VALUE "ProductName", "w32lib\0" - * - * Along with the fact that Sylpheed is under the GPL we can assume - * that this code is under the GPL. No author information or - * changelogs have been found. - * Files taken form the package are: - * w32_dirent.c w32_reg.c w32_stat.c w32_stdlib.c w32_time.c w32_wait.c - * w32_gettext.c w32_signal.c w32_stdio.c w32_string.c w32_unistd.c - */ - -/* Changes are: - -2007-05-21 Werner Koch <wk@g10code.com> - - * src/common/w32_account.c: New. - - * src/common/w32lib.h: Undef "interface". - -2005-11-17 Werner Koch <wk@g10code.com> - - Add boilerplate text to all files and explain legal status. - - * w32_reg.c: Replaced g_free and g_strdup by regular C functions. - (get_content_type_from_registry_with_ext): Ditto. - * w32_dirent.c (readdir): Ditto. - (opendir): Ditto. - (closedir): Reformatted. - (readdir): Reformatted, replaced use of g_strdup_printf and other - g-style malloc function by regular ones. Use DIR structure from mingw. - * w32lib.h: Don't define finddata_t for mingw. Replaced replacement - DIR structure by the one form mingw. Allocate filename in dirent - statically to match the defintion ussed by mingw. - * w32_reg.c (read_w32_registry_string): Return error for invalid root - key. - - */ - - -#ifndef _W32LIB_H_ -#define _W32LIB_H_ - -#include <windows.h> -#include <io.h> -#include <stdio.h> - -#ifdef __MINGW32__ -# include <_mingw.h> -# define MINGW32_VERSION (__MINGW32_MAJOR_VERSION * 100 \ - + __MINGW32_MINOR_VERSION) -# define MINGW64_VERSION (__MINGW64_VERSION_MAJOR * 100 \ - + __MINGW64_VERSION_MINOR) -# include <wchar.h> -# include <dirent.h> -# include <sys/time.h> -# if MINGW64_VERSION >= 200 -# include <sys/types.h> -# endif -#endif /* __MINGW32__ */ - -#include <glib/gstdio.h> - -/* Mingw32 3.4.4 defines interface to struct and thus breaks our own - use of that symbol. Undef it here. */ -#if defined(_BASETYPS_H) && defined(interface) -#undef interface -#endif - - -/* types */ -/*** ??? ***/ -#ifndef __MINGW32__ -typedef long int off_t; -typedef int pid_t; -typedef unsigned char u_char; -#endif /* __MINGW32__ */ -typedef unsigned int uid_t; - -#ifndef __MINGW32__ -/*** stat ***/ -#define S_IRUSR _S_IREAD -#define S_IWUSR _S_IWRITE -#define S_IXUSR _S_IEXEC -#define S_IRWXU (_S_IREAD|_S_IWRITE|_S_IEXEC) -#endif /* __MINGW32__ */ - - -/* (signal?) */ -#define SIGPIPE _S_IFIFO - - -/* (directory) */ -#define __S_ISTYPE(mode, mask) (((mode) & _S_IFMT) == (mask)) -#ifndef __MINGW32__ -#define S_ISFIFO(mode) __S_ISTYPE((mode), _S_IFIFO) -#define S_ISDIR(mode) __S_ISTYPE((mode), _S_IFDIR) -#define S_ISREG(mode) __S_ISTYPE((mode), _S_IFREG) -#endif /* __MINGW32__ */ - -/* functions */ -/*** str ***/ -#if MINGW64_VERSION < 200 -int strcasecmp( const char *s1, const char *s2 ); -int strncasecmp( const char *s1, const char *s2, size_t n ); -#endif - -/*** dir ***/ -#ifndef __MINGW32__ -typedef void * HANDLE; - -#ifndef _FINDDATA_T_DEFINED -typedef unsigned long _fsize_t; /* Could be 64 bits for Win32 */ -struct _finddata_t { - unsigned attrib; - time_t time_create; /* -1 for FAT file systems */ - time_t time_access; /* -1 for FAT file systems */ - time_t time_write; - _fsize_t size; - char name[260]; -}; -#endif /* !_FINDDATA_T_DEFINED */ - -struct dirent { - long d_ino; - unsigned short d_reclen; - unsigned short d_namlen; - char d_name[FILENAME_MAX]; -}; - -typedef struct -{ - struct _finddata_t dd_dta; - struct dirent dd_dir; - long dd_handle; - int dd_stat; - char dd_name[1]; -} DIR; - -#endif /* !__MINGW32__ */ - -#if defined (__MINGW32__) && MINGW32_VERSION < 312 -# if MINGW64_VERSION < 200 -struct timezone { - int tz_minuteswest; - int tz_dsttime; -}; -# endif -#endif - -/*** stat ***/ -int lstat( const char *file_name, GStatBuf *buf ); - -/*** sys/wait ***/ -pid_t waitpid( pid_t pid, int *status, int options ); - -/*** sys/time ***/ -#if ! defined (__MINGW32__) || MINGW32_VERSION < 312 -# if MINGW64_VERSION < 200 -int gettimeofday( struct timeval *tv, struct timezone *tz ); -# endif -#endif - -/*** unistd ***/ -int setpgid( pid_t pid, pid_t pgid ); -pid_t getppid( void ); -unsigned int sleep( unsigned int seconds ); - -/*** stdlib ***/ -long int random( void ); -void srandom( unsigned int seed ); -#if MINGW64_VERSION < 200 -int truncate( const char *path, off_t length ); -#endif - -/*** signal ***/ -int kill( pid_t pid, int sig ); - -/*** stdio ***/ -#if MINGW64_VERSION < 200 -FILE *popen( const char *command, const char *type ); -int pclose( FILE *stream ); -#endif - -/*** w32_account.c ***/ -int w32_is_administrator (void); - -/*** misc ***/ -int write_w32_registry_string( char *parent, char *section, char *value, char *data ); -int write_w32_registry_dword( char *parent, char *section, char *value, int data ); -char *read_w32_registry_string( char *parent, char *section, char *key ); -char *get_content_type_from_registry_with_ext( char *ext ); - -#endif diff --git a/src/exporthtml.c b/src/exporthtml.c @@ -38,10 +38,6 @@ #include <glib.h> #include <glib/gi18n.h> -#ifdef G_OS_WIN32 -# include <w32lib.h> -#endif - #include "mgutils.h" #include "utils.h" #include "exporthtml.h" diff --git a/src/folder.c b/src/folder.c @@ -31,9 +31,6 @@ #include <sys/stat.h> #include <unistd.h> #include <stdlib.h> -#ifdef WIN32 -#include <w32lib.h> -#endif #include "alertpanel.h" #include "folder.h" diff --git a/src/mainwindow.c b/src/mainwindow.c @@ -98,7 +98,7 @@ #include "printing.h" #include "send_message.h" #ifdef G_OS_WIN32 -#include "w32lib.h" +#include "w32_reg.h" #endif #define AC_LABEL_WIDTH 240 @@ -5157,7 +5157,7 @@ static void set_default_client_cb(GtkAction *action, gpointer data) gchar *binary_icon = NULL; gchar *binary_compose = NULL; gchar *binary_run = NULL; - int r = 0; + gboolean r; if ( !GetModuleFileNameA (0, exename, sizeof (exename)) ) { alertpanel_error(_("Can not register as default client: impossible to get executable path.")); return; @@ -5167,56 +5167,88 @@ static void set_default_client_cb(GtkAction *action, gpointer data) binary_run = g_strconcat(exename, NULL); /* Try to set the Mail Start menu item to Claws. It may fail if we're not root; we don't care */ - r = write_w32_registry_string("HKLM", "Software\\Clients\\Mail", - "", "Claws Mail"); + r = write_w32_registry_string(HKEY_LOCAL_MACHINE, + "Software\\Clients\\Mail", + "", + "Claws Mail"); - r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail", - "", "Claws Mail"); - if (!r) - r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail", - "DLLPath", ""); - if (!r) - r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", - "", "URL:MailTo-Protocol"); - if (!r) - r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", - "URL Protocol", ""); - if (!r) - r = write_w32_registry_dword ("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", - "EditFlags", 2); - if (!r) - r = write_w32_registry_string ("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", - "FriendlyTypeName", "Claws-Mail URL"); - if (!r) - r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto\\DefaultIcon", - "", binary_icon); - if (!r) - r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto\\shell\\open\\command", - "", binary_compose); - if (!r) - r = write_w32_registry_string("HKCU", "Software\\Clients\\Mail\\Claws Mail\\shell\\open\\command", - "", binary_run); + r = write_w32_registry_string(HKEY_CURRENT_USER, + "Software\\Clients\\Mail\\Claws Mail", + "", + "Claws Mail"); + if (r) + r = write_w32_registry_string(HKEY_CURRENT_USER, + "Software\\Clients\\Mail\\Claws Mail", + "DLLPath", + ""); + if (r) + r = write_w32_registry_string(HKEY_CURRENT_USER, + "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", + "", + "URL:MailTo-Protocol"); + if (r) + r = write_w32_registry_string(HKEY_CURRENT_USER, + "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", + "URL Protocol", + ""); + if (r) + r = write_w32_registry_dword (HKEY_CURRENT_USER, + "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", + "EditFlags", + 2); + if (r) + r = write_w32_registry_string(HKEY_CURRENT_USER, + "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto", + "FriendlyTypeName", + "Claws-Mail URL"); + if (r) + r = write_w32_registry_string(HKEY_CURRENT_USER, + "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto\\DefaultIcon", + "", + binary_icon); + if (r) + r = write_w32_registry_string(HKEY_CURRENT_USER, + "Software\\Clients\\Mail\\Claws Mail\\Protocols\\mailto\\shell\\open\\command", + "", + binary_compose); + if (r) + r = write_w32_registry_string(HKEY_CURRENT_USER, + "Software\\Clients\\Mail\\Claws Mail\\shell\\open\\command", + "", + binary_run); - if (!r) - r = write_w32_registry_string("HKCU", "Software\\Classes\\mailto", - "", "URL:MailTo-Protocol"); - if (!r) - r = write_w32_registry_string("HKCU", "Software\\Classes\\mailto", - "URL Protocol", ""); - if (!r) - r = write_w32_registry_dword ("HKCU", "Software\\Classes\\mailto", - "EditFlags", 2); - if (!r) - r = write_w32_registry_string("HKCU", "Software\\Classes\\mailto", - "FriendlyTypeName", "Claws-Mail URL"); - if (!r) - r = write_w32_registry_string("HKCU", "Software\\Classes\\mailto\\DefaultIcon", - "", binary_icon); - if (!r) - r = write_w32_registry_string("HKCU", "Software\\Classes\\mailto\\shell\\open\\command", - "", binary_compose); + if (r) + r = write_w32_registry_string(HKEY_CURRENT_USER, + "Software\\Classes\\mailto", + "", + "URL:MailTo-Protocol"); + if (r) + r = write_w32_registry_string(HKEY_CURRENT_USER, + "Software\\Classes\\mailto", + "URL Protocol", + ""); + if (r) + r = write_w32_registry_dword (HKEY_CURRENT_USER, + "Software\\Classes\\mailto", + "EditFlags", + 2); + if (r) + r = write_w32_registry_string(HKEY_CURRENT_USER, + "Software\\Classes\\mailto", + "FriendlyTypeName", + "Claws-Mail URL"); + if (r) + r = write_w32_registry_string(HKEY_CURRENT_USER, + "Software\\Classes\\mailto\\DefaultIcon", + "", + binary_icon); + if (r) + r = write_w32_registry_string(HKEY_CURRENT_USER, + "Software\\Classes\\mailto\\shell\\open\\command", + "", + binary_compose); - if (!r) { + if (r) { SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Software\\Clients\\Mail"); alertpanel_notice(_("Claws Mail has been registered as default client.")); } else { diff --git a/src/mbox.c b/src/mbox.c @@ -41,10 +41,6 @@ #include <time.h> #include <errno.h> -#ifdef G_OS_WIN32 -# include <w32lib.h> -#endif - #include "mbox.h" #include "procmsg.h" #include "folder.h" diff --git a/src/msgcache.c b/src/msgcache.c @@ -29,7 +29,6 @@ #include <glib.h> #include <glib/gi18n.h> #ifdef _WIN32 -# include <w32lib.h> # define MAP_FAILED ((char *) -1) #else # include <sys/mman.h> diff --git a/src/plugins/pgpcore/passphrase.c b/src/plugins/pgpcore/passphrase.c @@ -32,7 +32,7 @@ #include <string.h> #include <sys/types.h> #ifdef G_OS_WIN32 -#include <w32lib.h> +#include <windows.h> #else #include <sys/mman.h> #endif diff --git a/src/prefs_summaries.c b/src/prefs_summaries.c @@ -31,10 +31,6 @@ #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> -#ifdef G_OS_WIN32 -# include <w32lib.h> -#endif - #include "prefs_common.h" #include "prefs_gtk.h" #include "prefs_summary_open.h" diff --git a/src/procheader.c b/src/procheader.c @@ -30,10 +30,6 @@ #include <time.h> #include <sys/stat.h> -#ifdef G_OS_WIN32 -# include <w32lib.h> -#endif - #include "procheader.h" #include "procmsg.h" #include "codeconv.h" diff --git a/src/procmime.c b/src/procmime.c @@ -54,6 +54,11 @@ #include "account.h" #include "file-utils.h" +#ifdef G_OS_WIN32 +#include "w32_reg.h" +#define REG_MIME_TYPE_VALUE "Content Type" +#endif + static GHashTable *procmime_get_mime_type_table (void); static MimeInfo *procmime_scan_file_short(const gchar *filename); static MimeInfo *procmime_scan_queue_file_short(const gchar *filename); @@ -1082,6 +1087,7 @@ gchar *procmime_get_mime_type(const gchar *filename) const gchar *p; gchar *ext = NULL; gchar *base; + gchar *str; #ifndef G_OS_WIN32 static GHashTable *mime_type_table = NULL; MimeType *mime_type; @@ -1097,7 +1103,11 @@ gchar *procmime_get_mime_type(const gchar *filename) base = g_path_get_basename(filename); if ((p = strrchr(base, '.')) != NULL) +#ifndef G_OS_WIN32 ext = g_utf8_strdown(p + 1, -1); +#else + ext = g_utf8_strdown(p, -1); +#endif else ext = g_utf8_strdown(base, -1); g_free(base); @@ -1106,7 +1116,6 @@ gchar *procmime_get_mime_type(const gchar *filename) mime_type = g_hash_table_lookup(mime_type_table, ext); if (mime_type) { - gchar *str; str = g_strconcat(mime_type->type, "/", mime_type->sub_type, NULL); debug_print("got type %s for %s\n", str, ext); @@ -1116,8 +1125,8 @@ gchar *procmime_get_mime_type(const gchar *filename) g_free(ext); return NULL; #else - gchar *str = get_content_type_from_registry_with_ext(ext); - + str = read_w32_registry_string(HKEY_CLASSES_ROOT, ext, REG_MIME_TYPE_VALUE); + debug_print("got type %s for %s\n", str, ext); g_free(ext); return str; #endif diff --git a/src/recv.c b/src/recv.c @@ -30,9 +30,7 @@ #include <string.h> #include <unistd.h> -#ifdef G_OS_WIN32 -#include "w32lib.h" -#else +#ifndef G_OS_WIN32 #include <sys/time.h> #endif