--- /dev/null
+Return-Path: <bijan.chokoufe@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 989206DE01EA\r
+ for <notmuch@notmuchmail.org>; Sat, 14 May 2016 08:16:29 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.531\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.531 tagged_above=-999 required=5\r
+ tests=[AWL=-0.061, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,\r
+ FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001,\r
+ HEADER_FROM_DIFFERENT_DOMAINS=0.001, RCVD_IN_DNSWL_LOW=-0.7,\r
+ RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id oOavauwDgjg0 for <notmuch@notmuchmail.org>;\r
+ Sat, 14 May 2016 08:16:21 -0700 (PDT)\r
+Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com\r
+ [74.125.82.66]) by arlo.cworth.org (Postfix) with ESMTPS id A2B656DE01D0 for\r
+ <notmuch@notmuchmail.org>; Sat, 14 May 2016 08:16:20 -0700 (PDT)\r
+Received: by mail-wm0-f66.google.com with SMTP id w143so9252784wmw.3\r
+ for <notmuch@notmuchmail.org>; Sat, 14 May 2016 08:16:20 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=sender:from:to:cc:subject:date:message-id;\r
+ bh=0eUoOLuLsViVEB7I24ou8Os2MaZ6iLIM5B4ybvgUUxo=;\r
+ b=QwB2fn85UZ8HemuBvHZEOQEx2Kym3l/rcsFXqba/lb9G8iptBhGpUSzSovJzEFzYzU\r
+ tj0GigBXbTwBW4967qk4uCyS6jhixwgbNrmHa3PWWgGYqsEQCboJZLLnSdMD4YiokKHW\r
+ KhTPjiNudtHL8QiuyFpld5E3muXI7GMPBC9OE1YpHe/H+KxOCQF9E5cM1L8s9wvX/UR2\r
+ sIsyP/e1TktkWKfCW6J+zSxwf6jJ9XSEkGip4dvBbZ8Vh82N+BDAvNW9mUeBvvD+fIHW\r
+ ElQkh9IWaezaKfEeD6GYeBczc+luRNdT7ndVYt85HKk7NpHC4tzUj4/jpsRhMD1zUAfq\r
+ nVtQ==\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:sender:from:to:cc:subject:date:message-id;\r
+ bh=0eUoOLuLsViVEB7I24ou8Os2MaZ6iLIM5B4ybvgUUxo=;\r
+ b=O3OJ++fLX4iFbvfqvzB89lbcovRjLcKV1Ujjz7A1bpE218EJF+9P4rvyPBhEgFpTGN\r
+ OlNP6Zq1ZnNCrkMD1uEcRlNJFbvYGvdS7NTT9oe6IRcAADwRU5jUUSMLZydKSX23gA4w\r
+ S2qWkgSy6tLjJ/wwOF8UnxaD6jG60GeC5BzMRnssWMhWH3TPjG4eHhZHSwYfKHI5f8Mm\r
+ lfv9NM+fToTGOshoNHBaQJsXFSkqXKFYCv7ZP7b8/mFZ57KaQzRfKF43gOpkhEOl3RfA\r
+ dgzfFjrTDcT9sPiMrRnh3VJNIadfKUJFW1yQw87U9ikXXSH8rdFn36soOD0o1w6G19yf\r
+ rxsA==\r
+X-Gm-Message-State:\r
+ AOPr4FV20IKDPQ3/4Y1JglVWbQhyi+4UQRMHVR/aAF1+Qy8GsIKvg+mk0fqjjNDnANZS8w==\r
+X-Received: by 10.194.59.108 with SMTP id y12mr20565048wjq.63.1463238978863;\r
+ Sat, 14 May 2016 08:16:18 -0700 (PDT)\r
+Received: from localhost.localdomain (ip5f5be327.dynamic.kabel-deutschland.de.\r
+ [95.91.227.39])\r
+ by smtp.gmail.com with ESMTPSA id u4sm24112394wjz.4.2016.05.14.08.16.17\r
+ (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\r
+ Sat, 14 May 2016 08:16:17 -0700 (PDT)\r
+Sender: Bijan Chokoufe <bijan.chokoufe@gmail.com>\r
+From: Bijan Chokoufe Nejad <bijan@chokoufe.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3] config: Expand ~ to $HOME\r
+Date: Sat, 14 May 2016 17:15:49 +0200\r
+Message-Id: <1463238949-22612-1-git-send-email-bijan@chokoufe.com>\r
+X-Mailer: git-send-email 2.7.4\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 14 May 2016 15:16:29 -0000\r
+\r
+Very useful in case you want to keep your .notmuch-config synchronized across\r
+machines where you have different user names.\r
+\r
+---\r
+v2: Check for '~/' instead of checking for '~' and fix memory issue.\r
+ Unit test is still pending\r
+v3: Extended implementation handling also '~foo/' and '~foo'\r
+---\r
+ notmuch-config.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 46 insertions(+)\r
+\r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index 01bb185..25668a6 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -602,9 +602,55 @@ _config_set_list (notmuch_config_t *config,\r
+ *config_var = NULL;\r
+ }\r
+ \r
++static char *\r
++_config_get_user_folder (notmuch_config_t *config, const char *path) {\r
++ char* tmp = talloc_strdup (config, path + 1);\r
++ const char* user;\r
++ if (strpbrk(tmp, "/") != NULL) {\r
++ user = strtok (tmp, "/");\r
++ }\r
++ else {\r
++ user = tmp;\r
++ }\r
++ struct passwd * pwd = getpwnam (user);\r
++\r
++ if (pwd == NULL) {\r
++ printf("Config: could not expand %s.\n", path);\r
++ printf("'%s' doesn't seem to be a valid user on this system.\n", user);\r
++ exit(EXIT_FAILURE);\r
++ }\r
++\r
++ tmp = talloc_asprintf (config, "%s/%s", pwd->pw_dir, path + strlen (user) + 2);\r
++ return tmp;\r
++}\r
++\r
++static void\r
++_config_expand_path (notmuch_config_t *config) {\r
++ char* path = (char*) _config_get (config, &config->database_path,\r
++ "database", "path");\r
++ if (path != NULL && path[0] == '~') {\r
++ char *new_path;\r
++ if (strlen (path) == 1 || path[1] == '/') {\r
++ const char *home_path = getenv("HOME");\r
++ if (strlen (path) == 1)\r
++ new_path = talloc_asprintf (config, "%s%s", home_path, path + 1);\r
++ else if (path[1] == '/')\r
++ new_path = talloc_asprintf (config, "%s/%s", home_path, path + 2);\r
++ }\r
++ else {\r
++ new_path = _config_get_user_folder (config, path);\r
++ }\r
++ notmuch_config_set_database_path (config, new_path);\r
++ talloc_free (new_path);\r
++ }\r
++}\r
++\r
+ const char *\r
+ notmuch_config_get_database_path (notmuch_config_t *config)\r
+ {\r
++ // ideally a get_database_path should only get the database path and this\r
++ // call to _config_expand_path would be done in a setup phase\r
++ _config_expand_path (config);\r
+ return _config_get (config, &config->database_path, "database", "path");\r
+ }\r
+ \r
+-- \r
+2.7.4\r
+\r