--- /dev/null
+Return-Path: <teythoon@jade-hamburg.de>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 53297431FC3\r
+ for <notmuch@notmuchmail.org>; Wed, 9 May 2012 04:16:59 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id do-Gl7X3Cjep for <notmuch@notmuchmail.org>;\r
+ Wed, 9 May 2012 04:16:41 -0700 (PDT)\r
+Received: from mail.cryptobitch.de (cryptobitch.de [88.198.7.68])\r
+ (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id B7AAA431FAE\r
+ for <notmuch@notmuchmail.org>; Wed, 9 May 2012 04:16:40 -0700 (PDT)\r
+Received: from mail.jade-hamburg.de (mail.jade-hamburg.de [85.183.11.228])\r
+ (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by mail.cryptobitch.de (Postfix) with ESMTPSA id 39B25588C1D\r
+ for <notmuch@notmuchmail.org>; Wed, 9 May 2012 13:16:39 +0200 (CEST)\r
+Received: by mail.jade-hamburg.de (Postfix, from userid 401)\r
+ id D6E8CDF2A3; Wed, 9 May 2012 13:16:23 +0200 (CEST)\r
+Received: from thinkbox.jade-hamburg.de (mail.jade-hamburg.de [85.183.11.228])\r
+ (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
+ (No client certificate requested) (Authenticated sender: teythoon)\r
+ by mail.jade-hamburg.de (Postfix) with ESMTPSA id C73E4DF2A1;\r
+ Wed, 9 May 2012 13:15:18 +0200 (CEST)\r
+Received: from teythoon by thinkbox.jade-hamburg.de with local (Exim 4.77)\r
+ (envelope-from <teythoon@thinkbox.jade-hamburg.de>)\r
+ id 1SS4rj-0003cW-1k; Wed, 09 May 2012 13:15:31 +0200\r
+From: Justus Winter <4winter@informatik.uni-hamburg.de>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/5] go: reorganize the go bindings\r
+Date: Wed, 9 May 2012 13:15:16 +0200\r
+Message-Id:\r
+ <1336562120-13837-2-git-send-email-4winter@informatik.uni-hamburg.de>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To:\r
+ <1336562120-13837-1-git-send-email-4winter@informatik.uni-hamburg.de>\r
+References: <20120505111535.3687.9018@thinkbox.jade-hamburg.de>\r
+ <1336562120-13837-1-git-send-email-4winter@informatik.uni-hamburg.de>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://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: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 09 May 2012 11:16:59 -0000\r
+\r
+go 1 introduced the "go" program that simplifies building of libraries\r
+and programs. This patch reorganizes the go code so it can be compiled\r
+using the new utility, it does not change any files.\r
+\r
+Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>\r
+---\r
+ bindings/go/cmds/notmuch-addrlookup.go | 263 -----\r
+ bindings/go/pkg/notmuch.go | 1125 ----------------------\r
+ bindings/go/src/notmuch-addrlookup/addrlookup.go | 263 +++++\r
+ bindings/go/src/notmuch/notmuch.go | 1125 ++++++++++++++++++++++\r
+ 4 files changed, 1388 insertions(+), 1388 deletions(-)\r
+ delete mode 100644 bindings/go/cmds/notmuch-addrlookup.go\r
+ delete mode 100644 bindings/go/pkg/notmuch.go\r
+ create mode 100644 bindings/go/src/notmuch-addrlookup/addrlookup.go\r
+ create mode 100644 bindings/go/src/notmuch/notmuch.go\r
+\r
+diff --git a/bindings/go/cmds/notmuch-addrlookup.go b/bindings/go/cmds/notmuch-addrlookup.go\r
+deleted file mode 100644\r
+index 03699fb..0000000\r
+--- a/bindings/go/cmds/notmuch-addrlookup.go\r
++++ /dev/null\r
+@@ -1,263 +0,0 @@\r
+-package main\r
+-\r
+-// stdlib imports\r
+-import "os"\r
+-import "path"\r
+-import "log"\r
+-import "fmt"\r
+-import "regexp"\r
+-import "strings"\r
+-import "sort"\r
+-\r
+-// 3rd-party imports\r
+-import "notmuch"\r
+-import "github.com/kless/goconfig/config"\r
+-\r
+-type mail_addr_freq struct {\r
+- addr string\r
+- count [3]uint\r
+-}\r
+-\r
+-type frequencies map[string]uint\r
+-\r
+-/* Used to sort the email addresses from most to least used */\r
+-func sort_by_freq(m1, m2 *mail_addr_freq) int {\r
+- if (m1.count[0] == m2.count[0] &&\r
+- m1.count[1] == m2.count[1] &&\r
+- m1.count[2] == m2.count[2]) {\r
+- return 0\r
+- }\r
+-\r
+- if (m1.count[0] > m2.count[0] ||\r
+- m1.count[0] == m2.count[0] &&\r
+- m1.count[1] > m2.count[1] ||\r
+- m1.count[0] == m2.count[0] &&\r
+- m1.count[1] == m2.count[1] &&\r
+- m1.count[2] > m2.count[2]) {\r
+- return -1\r
+- }\r
+-\r
+- return 1\r
+-}\r
+-\r
+-type maddresses []*mail_addr_freq\r
+-\r
+-func (self *maddresses) Len() int {\r
+- return len(*self)\r
+-}\r
+-\r
+-func (self *maddresses) Less(i,j int) bool {\r
+- m1 := (*self)[i]\r
+- m2 := (*self)[j]\r
+- v := sort_by_freq(m1, m2)\r
+- if v<=0 {\r
+- return true\r
+- }\r
+- return false\r
+-}\r
+-\r
+-func (self *maddresses) Swap(i,j int) {\r
+- (*self)[i], (*self)[j] = (*self)[j], (*self)[i]\r
+-}\r
+-\r
+-// find most frequent real name for each mail address\r
+-func frequent_fullname(freqs frequencies) string {\r
+- var maxfreq uint = 0\r
+- fullname := ""\r
+- freqs_sz := len(freqs)\r
+-\r
+- for mail,freq := range freqs {\r
+- if (freq > maxfreq && mail != "") || freqs_sz == 1 {\r
+- // only use the entry if it has a real name\r
+- // or if this is the only entry\r
+- maxfreq = freq\r
+- fullname = mail\r
+- }\r
+- }\r
+- return fullname\r
+-}\r
+-\r
+-func addresses_by_frequency(msgs *notmuch.Messages, name string, pass uint, addr_to_realname *map[string]*frequencies) *frequencies {\r
+-\r
+- freqs := make(frequencies)\r
+-\r
+- pattern := `\s*(("(\.|[^"])*"|[^,])*<?(?mail\b\w+([-+.]\w+)*\@\w+[-\.\w]*\.([-\.\w]+)*\w\b)>?)`\r
+- // pattern := "\\s*((\\\"(\\\\.|[^\\\\\"])*\\\"|[^,])*" +\r
+- // "<?(?P<mail>\\b\\w+([-+.]\\w+)*\\@\\w+[-\\.\\w]*\\.([-\\.\\w]+)*\\w\\b)>?)"\r
+- pattern = `.*` + strings.ToLower(name) + `.*`\r
+- var re *regexp.Regexp = nil\r
+- var err os.Error = nil\r
+- if re,err = regexp.Compile(pattern); err != nil {\r
+- log.Printf("error: %v\n", err)\r
+- return &freqs\r
+- }\r
+- \r
+- headers := []string{"from"}\r
+- if pass == 1 {\r
+- headers = append(headers, "to", "cc", "bcc")\r
+- }\r
+-\r
+- for ;msgs.Valid();msgs.MoveToNext() {\r
+- msg := msgs.Get()\r
+- //println("==> msg [", msg.GetMessageId(), "]")\r
+- for _,header := range headers {\r
+- froms := strings.ToLower(msg.GetHeader(header))\r
+- //println(" froms: ["+froms+"]")\r
+- for _,from := range strings.Split(froms, ",", -1) {\r
+- from = strings.Trim(from, " ")\r
+- match := re.FindString(from)\r
+- //println(" -> match: ["+match+"]")\r
+- occ,ok := freqs[match]\r
+- if !ok {\r
+- freqs[match] = 0\r
+- occ = 0\r
+- }\r
+- freqs[match] = occ+1\r
+- }\r
+- }\r
+- }\r
+- return &freqs\r
+-}\r
+-\r
+-func search_address_passes(queries [3]*notmuch.Query, name string) []string {\r
+- var val []string\r
+- addr_freq := make(map[string]*mail_addr_freq)\r
+- addr_to_realname := make(map[string]*frequencies)\r
+-\r
+- var pass uint = 0 // 0-based\r
+- for _,query := range queries {\r
+- if query == nil {\r
+- //println("**warning: idx [",idx,"] contains a nil query")\r
+- continue\r
+- }\r
+- msgs := query.SearchMessages()\r
+- ht := addresses_by_frequency(msgs, name, pass, &addr_to_realname)\r
+- for addr, count := range *ht {\r
+- freq,ok := addr_freq[addr]\r
+- if !ok {\r
+- freq = &mail_addr_freq{addr:addr, count:[3]uint{0,0,0}}\r
+- }\r
+- freq.count[pass] = count\r
+- addr_freq[addr] = freq\r
+- }\r
+- msgs.Destroy()\r
+- pass += 1\r
+- }\r
+-\r
+- addrs := make(maddresses, len(addr_freq))\r
+- {\r
+- iaddr := 0\r
+- for _, freq := range addr_freq {\r
+- addrs[iaddr] = freq\r
+- iaddr += 1\r
+- }\r
+- }\r
+- sort.Sort(&addrs)\r
+-\r
+- for _,addr := range addrs {\r
+- freqs,ok := addr_to_realname[addr.addr]\r
+- if ok {\r
+- val = append(val, frequent_fullname(*freqs))\r
+- } else {\r
+- val = append(val, addr.addr)\r
+- }\r
+- }\r
+- //println("val:",val)\r
+- return val\r
+-}\r
+-\r
+-type address_matcher struct {\r
+- // the notmuch database\r
+- db *notmuch.Database\r
+- // full path of the notmuch database\r
+- user_db_path string\r
+- // user primary email\r
+- user_primary_email string\r
+- // user tag to mark from addresses as in the address book\r
+- user_addrbook_tag string\r
+-}\r
+-\r
+-func new_address_matcher() *address_matcher {\r
+- var cfg *config.Config\r
+- var err os.Error\r
+-\r
+- // honor NOTMUCH_CONFIG\r
+- home := os.Getenv("NOTMUCH_CONFIG")\r
+- if home == "" {\r
+- home = os.Getenv("HOME")\r
+- }\r
+-\r
+- if cfg,err = config.ReadDefault(path.Join(home, ".notmuch-config")); err != nil {\r
+- log.Fatalf("error loading config file:",err)\r
+- }\r
+-\r
+- db_path,_ := cfg.String("database", "path")\r
+- primary_email,_ := cfg.String("user", "primary_email")\r
+- addrbook_tag,err := cfg.String("user", "addrbook_tag")\r
+- if err != nil {\r
+- addrbook_tag = "addressbook"\r
+- }\r
+-\r
+- self := &address_matcher{db:nil, \r
+- user_db_path:db_path,\r
+- user_primary_email:primary_email,\r
+- user_addrbook_tag:addrbook_tag}\r
+- return self\r
+-}\r
+-\r
+-func (self *address_matcher) run(name string) {\r
+- queries := [3]*notmuch.Query{}\r
+- \r
+- // open the database\r
+- if db, status := notmuch.OpenDatabase(self.user_db_path,\r
+- notmuch.DATABASE_MODE_READ_ONLY); status == notmuch.STATUS_SUCCESS {\r
+- self.db = db\r
+- } else {\r
+- log.Fatalf("Failed to open the database: %v\n", status)\r
+- }\r
+-\r
+- // pass 1: look at all from: addresses with the address book tag\r
+- query := "tag:" + self.user_addrbook_tag\r
+- if name != "" {\r
+- query = query + " and from:" + name + "*"\r
+- }\r
+- queries[0] = self.db.CreateQuery(query)\r
+-\r
+- // pass 2: look at all to: addresses sent from our primary mail\r
+- query = ""\r
+- if name != "" {\r
+- query = "to:"+name+"*"\r
+- }\r
+- if self.user_primary_email != "" {\r
+- query = query + " from:" + self.user_primary_email\r
+- }\r
+- queries[1] = self.db.CreateQuery(query)\r
+-\r
+- // if that leads only to a few hits, we check every from too\r
+- if queries[0].CountMessages() + queries[1].CountMessages() < 10 {\r
+- query = ""\r
+- if name != "" {\r
+- query = "from:"+name+"*"\r
+- }\r
+- queries[2] = self.db.CreateQuery(query)\r
+- }\r
+- \r
+- // actually retrieve and sort addresses\r
+- results := search_address_passes(queries, name)\r
+- for _,v := range results {\r
+- if v != "" && v != "\n" {\r
+- fmt.Println(v)\r
+- }\r
+- }\r
+- return\r
+-}\r
+-\r
+-func main() {\r
+- //fmt.Println("args:",os.Args)\r
+- app := new_address_matcher()\r
+- name := ""\r
+- if len(os.Args) > 1 {\r
+- name = os.Args[1]\r
+- }\r
+- app.run(name)\r
+-}\r
+\ No newline at end of file\r
+diff --git a/bindings/go/pkg/notmuch.go b/bindings/go/pkg/notmuch.go\r
+deleted file mode 100644\r
+index 8faf3bb..0000000\r
+--- a/bindings/go/pkg/notmuch.go\r
++++ /dev/null\r
+@@ -1,1125 +0,0 @@\r
+-// Wrapper around the notmuch library\r
+-\r
+-package notmuch\r
+-\r
+-/*\r
+-#include <stdlib.h>\r
+-#include <string.h>\r
+-#include <time.h>\r
+-#include "notmuch.h"\r
+-*/\r
+-import "C"\r
+-import "unsafe"\r
+-\r
+-// Status codes used for the return values of most functions\r
+-type Status C.notmuch_status_t\r
+-const (\r
+- STATUS_SUCCESS Status = iota\r
+- STATUS_OUT_OF_MEMORY\r
+- STATUS_READ_ONLY_DATABASE\r
+- STATUS_XAPIAN_EXCEPTION\r
+- STATUS_FILE_ERROR\r
+- STATUS_FILE_NOT_EMAIL\r
+- STATUS_DUPLICATE_MESSAGE_ID\r
+- STATUS_NULL_POINTER\r
+- STATUS_TAG_TOO_LONG\r
+- STATUS_UNBALANCED_FREEZE_THAW\r
+- STATUS_UNBALANCED_ATOMIC\r
+-\r
+- STATUS_LAST_STATUS\r
+-)\r
+-\r
+-func (self Status) String() string {\r
+- var p *C.char\r
+- \r
+- // p is read-only\r
+- p = C.notmuch_status_to_string(C.notmuch_status_t(self))\r
+- if p != nil {\r
+- s := C.GoString(p)\r
+- return s\r
+- }\r
+- return ""\r
+-}\r
+-\r
+-/* Various opaque data types. For each notmuch_<foo>_t see the various\r
+- * notmuch_<foo> functions below. */\r
+-\r
+-type Database struct {\r
+- db *C.notmuch_database_t\r
+-}\r
+-\r
+-type Query struct {\r
+- query *C.notmuch_query_t\r
+-}\r
+-\r
+-type Threads struct {\r
+- threads *C.notmuch_threads_t\r
+-}\r
+-\r
+-type Thread struct {\r
+- thread *C.notmuch_thread_t\r
+-}\r
+-\r
+-type Messages struct {\r
+- messages *C.notmuch_messages_t\r
+-}\r
+-\r
+-type Message struct {\r
+- message *C.notmuch_message_t\r
+-}\r
+-\r
+-type Tags struct {\r
+- tags *C.notmuch_tags_t\r
+-}\r
+-\r
+-type Directory struct {\r
+- dir *C.notmuch_directory_t\r
+-}\r
+-\r
+-type Filenames struct {\r
+- fnames *C.notmuch_filenames_t\r
+-}\r
+-\r
+-type DatabaseMode C.notmuch_database_mode_t\r
+-const (\r
+- DATABASE_MODE_READ_ONLY DatabaseMode = 0\r
+- DATABASE_MODE_READ_WRITE\r
+-)\r
+-\r
+-// Create a new, empty notmuch database located at 'path'\r
+-func NewDatabase(path string) (*Database, Status) {\r
+-\r
+- var c_path *C.char = C.CString(path)\r
+- defer C.free(unsafe.Pointer(c_path))\r
+-\r
+- if c_path == nil {\r
+- return nil, STATUS_OUT_OF_MEMORY\r
+- }\r
+-\r
+- self := &Database{db:nil}\r
+- st := Status(C.notmuch_database_create(c_path, &self.db))\r
+- if st != STATUS_SUCCESS {\r
+- return nil, st\r
+- }\r
+- return self, st\r
+-}\r
+-\r
+-/* Open an existing notmuch database located at 'path'.\r
+- *\r
+- * The database should have been created at some time in the past,\r
+- * (not necessarily by this process), by calling\r
+- * notmuch_database_create with 'path'. By default the database should be\r
+- * opened for reading only. In order to write to the database you need to\r
+- * pass the NOTMUCH_DATABASE_MODE_READ_WRITE mode.\r
+- *\r
+- * An existing notmuch database can be identified by the presence of a\r
+- * directory named ".notmuch" below 'path'.\r
+- *\r
+- * The caller should call notmuch_database_destroy when finished with\r
+- * this database.\r
+- *\r
+- * In case of any failure, this function returns NULL, (after printing\r
+- * an error message on stderr).\r
+- */\r
+-func OpenDatabase(path string, mode DatabaseMode) (*Database, Status) {\r
+-\r
+- var c_path *C.char = C.CString(path)\r
+- defer C.free(unsafe.Pointer(c_path))\r
+-\r
+- if c_path == nil {\r
+- return nil, STATUS_OUT_OF_MEMORY\r
+- }\r
+-\r
+- self := &Database{db:nil}\r
+- st := Status(C.notmuch_database_open(c_path, C.notmuch_database_mode_t(mode), &self.db))\r
+- if st != STATUS_SUCCESS {\r
+- return nil, st\r
+- }\r
+- return self, st\r
+-}\r
+-\r
+-/* Close the given notmuch database, freeing all associated\r
+- * resources. See notmuch_database_open. */\r
+-func (self *Database) Close() {\r
+- C.notmuch_database_destroy(self.db)\r
+-}\r
+-\r
+-/* Return the database path of the given database.\r
+- */\r
+-func (self *Database) GetPath() string {\r
+- \r
+- /* The return value is a string owned by notmuch so should not be\r
+- * modified nor freed by the caller. */\r
+- var p *C.char = C.notmuch_database_get_path(self.db)\r
+- if p != nil {\r
+- s := C.GoString(p)\r
+- return s\r
+- }\r
+- return ""\r
+-}\r
+-\r
+-/* Return the database format version of the given database. */\r
+-func (self *Database) GetVersion() uint {\r
+- return uint(C.notmuch_database_get_version(self.db))\r
+-}\r
+-\r
+-/* Does this database need to be upgraded before writing to it?\r
+- *\r
+- * If this function returns TRUE then no functions that modify the\r
+- * database (notmuch_database_add_message, notmuch_message_add_tag,\r
+- * notmuch_directory_set_mtime, etc.) will work unless the function\r
+- * notmuch_database_upgrade is called successfully first. */\r
+-func (self *Database) NeedsUpgrade() bool {\r
+- do_upgrade := C.notmuch_database_needs_upgrade(self.db)\r
+- if do_upgrade == 0 {\r
+- return false\r
+- }\r
+- return true\r
+-}\r
+-\r
+-// TODO: notmuch_database_upgrade\r
+-\r
+-\r
+-/* Retrieve a directory object from the database for 'path'.\r
+- *\r
+- * Here, 'path' should be a path relative to the path of 'database'\r
+- * (see notmuch_database_get_path), or else should be an absolute path\r
+- * with initial components that match the path of 'database'.\r
+- *\r
+- * Can return NULL if a Xapian exception occurs.\r
+- */\r
+-func (self *Database) GetDirectory(path string) *Directory {\r
+- var c_path *C.char = C.CString(path)\r
+- defer C.free(unsafe.Pointer(c_path))\r
+-\r
+- if c_path == nil {\r
+- return nil\r
+- }\r
+-\r
+- c_dir := C.notmuch_database_get_directory(self.db, c_path)\r
+- if c_dir == nil {\r
+- return nil\r
+- }\r
+- return &Directory{dir:c_dir}\r
+-}\r
+-\r
+-/* Add a new message to the given notmuch database.\r
+- *\r
+- * Here,'filename' should be a path relative to the path of\r
+- * 'database' (see notmuch_database_get_path), or else should be an\r
+- * absolute filename with initial components that match the path of\r
+- * 'database'.\r
+- *\r
+- * The file should be a single mail message (not a multi-message mbox)\r
+- * that is expected to remain at its current location, (since the\r
+- * notmuch database will reference the filename, and will not copy the\r
+- * entire contents of the file.\r
+- *\r
+- * If 'message' is not NULL, then, on successful return '*message'\r
+- * will be initialized to a message object that can be used for things\r
+- * such as adding tags to the just-added message. The user should call\r
+- * notmuch_message_destroy when done with the message. On any failure\r
+- * '*message' will be set to NULL.\r
+- *\r
+- * Return value:\r
+- *\r
+- * NOTMUCH_STATUS_SUCCESS: Message successfully added to database.\r
+- *\r
+- * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred,\r
+- * message not added.\r
+- *\r
+- * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: Message has the same message\r
+- * ID as another message already in the database. The new\r
+- * filename was successfully added to the message in the database\r
+- * (if not already present).\r
+- *\r
+- * NOTMUCH_STATUS_FILE_ERROR: an error occurred trying to open the\r
+- * file, (such as permission denied, or file not found,\r
+- * etc.). Nothing added to the database.\r
+- *\r
+- * NOTMUCH_STATUS_FILE_NOT_EMAIL: the contents of filename don't look\r
+- * like an email message. Nothing added to the database.\r
+- *\r
+- * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
+- * mode so no message can be added.\r
+- */\r
+-func \r
+-(self *Database) AddMessage(fname string) (*Message, Status) {\r
+- var c_fname *C.char = C.CString(fname)\r
+- defer C.free(unsafe.Pointer(c_fname))\r
+-\r
+- if c_fname == nil {\r
+- return nil, STATUS_OUT_OF_MEMORY\r
+- }\r
+-\r
+- var c_msg *C.notmuch_message_t = new(C.notmuch_message_t)\r
+- st := Status(C.notmuch_database_add_message(self.db, c_fname, &c_msg))\r
+-\r
+- return &Message{message:c_msg}, st\r
+-}\r
+-\r
+-/* Remove a message from the given notmuch database.\r
+- *\r
+- * Note that only this particular filename association is removed from\r
+- * the database. If the same message (as determined by the message ID)\r
+- * is still available via other filenames, then the message will\r
+- * persist in the database for those filenames. When the last filename\r
+- * is removed for a particular message, the database content for that\r
+- * message will be entirely removed.\r
+- *\r
+- * Return value:\r
+- *\r
+- * NOTMUCH_STATUS_SUCCESS: The last filename was removed and the\r
+- * message was removed from the database.\r
+- *\r
+- * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred,\r
+- * message not removed.\r
+- *\r
+- * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: This filename was removed but\r
+- * the message persists in the database with at least one other\r
+- * filename.\r
+- *\r
+- * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
+- * mode so no message can be removed.\r
+- */\r
+-func (self *Database) RemoveMessage(fname string) Status {\r
+- \r
+- var c_fname *C.char = C.CString(fname)\r
+- defer C.free(unsafe.Pointer(c_fname))\r
+-\r
+- if c_fname == nil {\r
+- return STATUS_OUT_OF_MEMORY\r
+- }\r
+-\r
+- st := C.notmuch_database_remove_message(self.db, c_fname)\r
+- return Status(st)\r
+-}\r
+-\r
+-/* Find a message with the given message_id.\r
+- *\r
+- * If the database contains a message with the given message_id, then\r
+- * a new notmuch_message_t object is returned. The caller should call\r
+- * notmuch_message_destroy when done with the message.\r
+- *\r
+- * This function returns NULL in the following situations:\r
+- *\r
+- * * No message is found with the given message_id\r
+- * * An out-of-memory situation occurs\r
+- * * A Xapian exception occurs\r
+- */\r
+-func (self *Database) FindMessage(message_id string) (*Message, Status) {\r
+- \r
+- var c_msg_id *C.char = C.CString(message_id)\r
+- defer C.free(unsafe.Pointer(c_msg_id))\r
+-\r
+- if c_msg_id == nil {\r
+- return nil, STATUS_OUT_OF_MEMORY\r
+- }\r
+-\r
+- msg := &Message{message:nil}\r
+- st := Status(C.notmuch_database_find_message(self.db, c_msg_id, &msg.message))\r
+- if st != STATUS_SUCCESS {\r
+- return nil, st\r
+- }\r
+- return msg, st\r
+-}\r
+-\r
+-/* Return a list of all tags found in the database.\r
+- *\r
+- * This function creates a list of all tags found in the database. The\r
+- * resulting list contains all tags from all messages found in the database.\r
+- *\r
+- * On error this function returns NULL.\r
+- */\r
+-func (self *Database) GetAllTags() *Tags {\r
+- tags := C.notmuch_database_get_all_tags(self.db)\r
+- if tags == nil {\r
+- return nil\r
+- }\r
+- return &Tags{tags:tags}\r
+-}\r
+-\r
+-/* Create a new query for 'database'.\r
+- *\r
+- * Here, 'database' should be an open database, (see\r
+- * notmuch_database_open and notmuch_database_create).\r
+- *\r
+- * For the query string, we'll document the syntax here more\r
+- * completely in the future, but it's likely to be a specialized\r
+- * version of the general Xapian query syntax:\r
+- *\r
+- * http://xapian.org/docs/queryparser.html\r
+- *\r
+- * As a special case, passing either a length-zero string, (that is ""),\r
+- * or a string consisting of a single asterisk (that is "*"), will\r
+- * result in a query that returns all messages in the database.\r
+- *\r
+- * See notmuch_query_set_sort for controlling the order of results.\r
+- * See notmuch_query_search_messages and notmuch_query_search_threads\r
+- * to actually execute the query.\r
+- *\r
+- * User should call notmuch_query_destroy when finished with this\r
+- * query.\r
+- *\r
+- * Will return NULL if insufficient memory is available.\r
+- */\r
+-func (self *Database) CreateQuery(query string) *Query {\r
+- \r
+- var c_query *C.char = C.CString(query)\r
+- defer C.free(unsafe.Pointer(c_query))\r
+-\r
+- if c_query == nil {\r
+- return nil\r
+- }\r
+-\r
+- q := C.notmuch_query_create(self.db, c_query)\r
+- if q == nil {\r
+- return nil\r
+- }\r
+- return &Query{query:q}\r
+-}\r
+-\r
+-/* Sort values for notmuch_query_set_sort */\r
+-type Sort C.notmuch_sort_t\r
+-const (\r
+- SORT_OLDEST_FIRST Sort = 0\r
+- SORT_NEWEST_FIRST\r
+- SORT_MESSAGE_ID\r
+- SORT_UNSORTED\r
+-)\r
+-\r
+-/* Return the query_string of this query. See notmuch_query_create. */\r
+-func (self *Query) String() string {\r
+- // FIXME: do we own 'q' or not ?\r
+- q := C.notmuch_query_get_query_string(self.query)\r
+- //defer C.free(unsafe.Pointer(q))\r
+- \r
+- if q != nil {\r
+- s := C.GoString(q)\r
+- return s\r
+- }\r
+-\r
+- return ""\r
+-}\r
+-\r
+-/* Specify the sorting desired for this query. */\r
+-func (self *Query) SetSort(sort Sort) {\r
+- C.notmuch_query_set_sort(self.query, C.notmuch_sort_t(sort))\r
+-}\r
+-\r
+-/* Return the sort specified for this query. See notmuch_query_set_sort. */\r
+-func (self *Query) GetSort() Sort {\r
+- return Sort(C.notmuch_query_get_sort(self.query))\r
+-}\r
+-\r
+-/* Execute a query for threads, returning a notmuch_threads_t object\r
+- * which can be used to iterate over the results. The returned threads\r
+- * object is owned by the query and as such, will only be valid until\r
+- * notmuch_query_destroy.\r
+- *\r
+- * Typical usage might be:\r
+- *\r
+- * notmuch_query_t *query;\r
+- * notmuch_threads_t *threads;\r
+- * notmuch_thread_t *thread;\r
+- *\r
+- * query = notmuch_query_create (database, query_string);\r
+- *\r
+- * for (threads = notmuch_query_search_threads (query);\r
+- * notmuch_threads_valid (threads);\r
+- * notmuch_threads_move_to_next (threads))\r
+- * {\r
+- * thread = notmuch_threads_get (threads);\r
+- * ....\r
+- * notmuch_thread_destroy (thread);\r
+- * }\r
+- *\r
+- * notmuch_query_destroy (query);\r
+- *\r
+- * Note: If you are finished with a thread before its containing\r
+- * query, you can call notmuch_thread_destroy to clean up some memory\r
+- * sooner (as in the above example). Otherwise, if your thread objects\r
+- * are long-lived, then you don't need to call notmuch_thread_destroy\r
+- * and all the memory will still be reclaimed when the query is\r
+- * destroyed.\r
+- *\r
+- * Note that there's no explicit destructor needed for the\r
+- * notmuch_threads_t object. (For consistency, we do provide a\r
+- * notmuch_threads_destroy function, but there's no good reason\r
+- * to call it if the query is about to be destroyed).\r
+- *\r
+- * If a Xapian exception occurs this function will return NULL.\r
+- */\r
+-func (self *Query) SearchThreads() *Threads {\r
+- threads := C.notmuch_query_search_threads(self.query)\r
+- if threads == nil {\r
+- return nil\r
+- }\r
+- return &Threads{threads:threads}\r
+-}\r
+-\r
+-/* Execute a query for messages, returning a notmuch_messages_t object\r
+- * which can be used to iterate over the results. The returned\r
+- * messages object is owned by the query and as such, will only be\r
+- * valid until notmuch_query_destroy.\r
+- *\r
+- * Typical usage might be:\r
+- *\r
+- * notmuch_query_t *query;\r
+- * notmuch_messages_t *messages;\r
+- * notmuch_message_t *message;\r
+- *\r
+- * query = notmuch_query_create (database, query_string);\r
+- *\r
+- * for (messages = notmuch_query_search_messages (query);\r
+- * notmuch_messages_valid (messages);\r
+- * notmuch_messages_move_to_next (messages))\r
+- * {\r
+- * message = notmuch_messages_get (messages);\r
+- * ....\r
+- * notmuch_message_destroy (message);\r
+- * }\r
+- *\r
+- * notmuch_query_destroy (query);\r
+- *\r
+- * Note: If you are finished with a message before its containing\r
+- * query, you can call notmuch_message_destroy to clean up some memory\r
+- * sooner (as in the above example). Otherwise, if your message\r
+- * objects are long-lived, then you don't need to call\r
+- * notmuch_message_destroy and all the memory will still be reclaimed\r
+- * when the query is destroyed.\r
+- *\r
+- * Note that there's no explicit destructor needed for the\r
+- * notmuch_messages_t object. (For consistency, we do provide a\r
+- * notmuch_messages_destroy function, but there's no good\r
+- * reason to call it if the query is about to be destroyed).\r
+- *\r
+- * If a Xapian exception occurs this function will return NULL.\r
+- */\r
+-func (self *Query) SearchMessages() *Messages {\r
+- msgs := C.notmuch_query_search_messages(self.query)\r
+- if msgs == nil {\r
+- return nil\r
+- }\r
+- return &Messages{messages:msgs}\r
+-}\r
+-\r
+-/* Destroy a notmuch_query_t along with any associated resources.\r
+- *\r
+- * This will in turn destroy any notmuch_threads_t and\r
+- * notmuch_messages_t objects generated by this query, (and in\r
+- * turn any notmuch_thread_t and notmuch_message_t objects generated\r
+- * from those results, etc.), if such objects haven't already been\r
+- * destroyed.\r
+- */\r
+-func (self *Query) Destroy() {\r
+- if self.query != nil {\r
+- C.notmuch_query_destroy(self.query)\r
+- }\r
+-}\r
+-\r
+-/* Return an estimate of the number of messages matching a search\r
+- *\r
+- * This function performs a search and returns Xapian's best\r
+- * guess as to number of matching messages.\r
+- *\r
+- * If a Xapian exception occurs, this function may return 0 (after\r
+- * printing a message).\r
+- */\r
+-func (self *Query) CountMessages() uint {\r
+- return uint(C.notmuch_query_count_messages(self.query))\r
+-}\r
+-\r
+-// TODO: wrap threads and thread\r
+-\r
+-/* Is the given 'threads' iterator pointing at a valid thread.\r
+- *\r
+- * When this function returns TRUE, notmuch_threads_get will return a\r
+- * valid object. Whereas when this function returns FALSE,\r
+- * notmuch_threads_get will return NULL.\r
+- *\r
+- * See the documentation of notmuch_query_search_threads for example\r
+- * code showing how to iterate over a notmuch_threads_t object.\r
+- */\r
+-func (self *Threads) Valid() bool {\r
+- if self.threads == nil {\r
+- return false\r
+- }\r
+- valid := C.notmuch_threads_valid(self.threads)\r
+- if valid == 0 {\r
+- return false\r
+- }\r
+- return true\r
+-}\r
+-\r
+-/* Destroy a notmuch_threads_t object.\r
+- *\r
+- * It's not strictly necessary to call this function. All memory from\r
+- * the notmuch_threads_t object will be reclaimed when the\r
+- * containg query object is destroyed.\r
+- */\r
+-func (self *Threads) Destroy() {\r
+- if self.threads != nil {\r
+- C.notmuch_threads_destroy(self.threads)\r
+- }\r
+-}\r
+-\r
+-/* Is the given 'messages' iterator pointing at a valid message.\r
+- *\r
+- * When this function returns TRUE, notmuch_messages_get will return a\r
+- * valid object. Whereas when this function returns FALSE,\r
+- * notmuch_messages_get will return NULL.\r
+- *\r
+- * See the documentation of notmuch_query_search_messages for example\r
+- * code showing how to iterate over a notmuch_messages_t object.\r
+- */\r
+-func (self *Messages) Valid() bool {\r
+- if self.messages == nil {\r
+- return false\r
+- }\r
+- valid := C.notmuch_messages_valid(self.messages)\r
+- if valid == 0 {\r
+- return false\r
+- }\r
+- return true\r
+-}\r
+-\r
+-/* Get the current message from 'messages' as a notmuch_message_t.\r
+- *\r
+- * Note: The returned message belongs to 'messages' and has a lifetime\r
+- * identical to it (and the query to which it belongs).\r
+- *\r
+- * See the documentation of notmuch_query_search_messages for example\r
+- * code showing how to iterate over a notmuch_messages_t object.\r
+- *\r
+- * If an out-of-memory situation occurs, this function will return\r
+- * NULL.\r
+- */\r
+-func (self *Messages) Get() *Message {\r
+- if self.messages == nil {\r
+- return nil\r
+- }\r
+- msg := C.notmuch_messages_get(self.messages)\r
+- if msg == nil {\r
+- return nil\r
+- }\r
+- return &Message{message:msg}\r
+-}\r
+-\r
+-/* Move the 'messages' iterator to the next message.\r
+- *\r
+- * If 'messages' is already pointing at the last message then the\r
+- * iterator will be moved to a point just beyond that last message,\r
+- * (where notmuch_messages_valid will return FALSE and\r
+- * notmuch_messages_get will return NULL).\r
+- *\r
+- * See the documentation of notmuch_query_search_messages for example\r
+- * code showing how to iterate over a notmuch_messages_t object.\r
+- */\r
+-func (self *Messages) MoveToNext() {\r
+- if self.messages == nil {\r
+- return\r
+- }\r
+- C.notmuch_messages_move_to_next(self.messages)\r
+-}\r
+-\r
+-/* Destroy a notmuch_messages_t object.\r
+- *\r
+- * It's not strictly necessary to call this function. All memory from\r
+- * the notmuch_messages_t object will be reclaimed when the containing\r
+- * query object is destroyed.\r
+- */\r
+-func (self *Messages) Destroy() {\r
+- if self.messages != nil {\r
+- C.notmuch_messages_destroy(self.messages)\r
+- }\r
+-}\r
+-\r
+-/* Return a list of tags from all messages.\r
+- *\r
+- * The resulting list is guaranteed not to contain duplicated tags.\r
+- *\r
+- * WARNING: You can no longer iterate over messages after calling this\r
+- * function, because the iterator will point at the end of the list.\r
+- * We do not have a function to reset the iterator yet and the only\r
+- * way how you can iterate over the list again is to recreate the\r
+- * message list.\r
+- *\r
+- * The function returns NULL on error.\r
+- */\r
+-func (self *Messages) CollectTags() *Tags {\r
+- if self.messages == nil {\r
+- return nil\r
+- }\r
+- tags := C.notmuch_messages_collect_tags(self.messages)\r
+- if tags == nil {\r
+- return nil\r
+- }\r
+- return &Tags{tags:tags}\r
+-}\r
+-\r
+-/* Get the message ID of 'message'.\r
+- *\r
+- * The returned string belongs to 'message' and as such, should not be\r
+- * modified by the caller and will only be valid for as long as the\r
+- * message is valid, (which is until the query from which it derived\r
+- * is destroyed).\r
+- *\r
+- * This function will not return NULL since Notmuch ensures that every\r
+- * message has a unique message ID, (Notmuch will generate an ID for a\r
+- * message if the original file does not contain one).\r
+- */\r
+-func (self *Message) GetMessageId() string {\r
+-\r
+- if self.message == nil {\r
+- return ""\r
+- }\r
+- id := C.notmuch_message_get_message_id(self.message)\r
+- // we dont own id\r
+- // defer C.free(unsafe.Pointer(id))\r
+- if id == nil {\r
+- return ""\r
+- }\r
+- return C.GoString(id)\r
+-}\r
+-\r
+-/* Get the thread ID of 'message'.\r
+- *\r
+- * The returned string belongs to 'message' and as such, should not be\r
+- * modified by the caller and will only be valid for as long as the\r
+- * message is valid, (for example, until the user calls\r
+- * notmuch_message_destroy on 'message' or until a query from which it\r
+- * derived is destroyed).\r
+- *\r
+- * This function will not return NULL since Notmuch ensures that every\r
+- * message belongs to a single thread.\r
+- */\r
+-func (self *Message) GetThreadId() string {\r
+- \r
+- if self.message == nil {\r
+- return ""\r
+- }\r
+- id := C.notmuch_message_get_thread_id(self.message)\r
+- // we dont own id\r
+- // defer C.free(unsafe.Pointer(id))\r
+- \r
+- if id == nil {\r
+- return ""\r
+- }\r
+-\r
+- return C.GoString(id)\r
+-}\r
+-\r
+-/* Get a notmuch_messages_t iterator for all of the replies to\r
+- * 'message'.\r
+- *\r
+- * Note: This call only makes sense if 'message' was ultimately\r
+- * obtained from a notmuch_thread_t object, (such as by coming\r
+- * directly from the result of calling notmuch_thread_get_\r
+- * toplevel_messages or by any number of subsequent\r
+- * calls to notmuch_message_get_replies).\r
+- *\r
+- * If 'message' was obtained through some non-thread means, (such as\r
+- * by a call to notmuch_query_search_messages), then this function\r
+- * will return NULL.\r
+- *\r
+- * If there are no replies to 'message', this function will return\r
+- * NULL. (Note that notmuch_messages_valid will accept that NULL\r
+- * value as legitimate, and simply return FALSE for it.)\r
+- */\r
+-func (self *Message) GetReplies() *Messages {\r
+- if self.message == nil {\r
+- return nil\r
+- }\r
+- msgs := C.notmuch_message_get_replies(self.message)\r
+- if msgs == nil {\r
+- return nil\r
+- }\r
+- return &Messages{messages:msgs}\r
+-}\r
+-\r
+-/* Get a filename for the email corresponding to 'message'.\r
+- *\r
+- * The returned filename is an absolute filename, (the initial\r
+- * component will match notmuch_database_get_path() ).\r
+- *\r
+- * The returned string belongs to the message so should not be\r
+- * modified or freed by the caller (nor should it be referenced after\r
+- * the message is destroyed).\r
+- *\r
+- * Note: If this message corresponds to multiple files in the mail\r
+- * store, (that is, multiple files contain identical message IDs),\r
+- * this function will arbitrarily return a single one of those\r
+- * filenames.\r
+- */\r
+-func (self *Message) GetFileName() string {\r
+- if self.message == nil {\r
+- return ""\r
+- }\r
+- fname := C.notmuch_message_get_filename(self.message)\r
+- // we dont own fname\r
+- // defer C.free(unsafe.Pointer(fname))\r
+- \r
+- if fname == nil {\r
+- return ""\r
+- }\r
+-\r
+- return C.GoString(fname)\r
+-}\r
+-\r
+-type Flag C.notmuch_message_flag_t\r
+-const (\r
+- MESSAGE_FLAG_MATCH Flag = 0\r
+-)\r
+-\r
+-/* Get a value of a flag for the email corresponding to 'message'. */\r
+-func (self *Message) GetFlag(flag Flag) bool {\r
+- if self.message == nil {\r
+- return false\r
+- }\r
+- v := C.notmuch_message_get_flag(self.message, C.notmuch_message_flag_t(flag))\r
+- if v == 0 {\r
+- return false\r
+- }\r
+- return true\r
+-}\r
+-\r
+-/* Set a value of a flag for the email corresponding to 'message'. */\r
+-func (self *Message) SetFlag(flag Flag, value bool) {\r
+- if self.message == nil {\r
+- return\r
+- }\r
+- var v C.notmuch_bool_t = 0\r
+- if value {\r
+- v = 1\r
+- }\r
+- C.notmuch_message_set_flag(self.message, C.notmuch_message_flag_t(flag), v)\r
+-}\r
+-\r
+-// TODO: wrap notmuch_message_get_date\r
+-\r
+-/* Get the value of the specified header from 'message'.\r
+- *\r
+- * The value will be read from the actual message file, not from the\r
+- * notmuch database. The header name is case insensitive.\r
+- *\r
+- * The returned string belongs to the message so should not be\r
+- * modified or freed by the caller (nor should it be referenced after\r
+- * the message is destroyed).\r
+- *\r
+- * Returns an empty string ("") if the message does not contain a\r
+- * header line matching 'header'. Returns NULL if any error occurs.\r
+- */\r
+-func (self *Message) GetHeader(header string) string {\r
+- if self.message == nil {\r
+- return ""\r
+- }\r
+- \r
+- var c_header *C.char = C.CString(header)\r
+- defer C.free(unsafe.Pointer(c_header))\r
+- \r
+- /* we dont own value */\r
+- value := C.notmuch_message_get_header(self.message, c_header)\r
+- if value == nil {\r
+- return ""\r
+- }\r
+- \r
+- return C.GoString(value)\r
+-}\r
+-\r
+-/* Get the tags for 'message', returning a notmuch_tags_t object which\r
+- * can be used to iterate over all tags.\r
+- *\r
+- * The tags object is owned by the message and as such, will only be\r
+- * valid for as long as the message is valid, (which is until the\r
+- * query from which it derived is destroyed).\r
+- *\r
+- * Typical usage might be:\r
+- *\r
+- * notmuch_message_t *message;\r
+- * notmuch_tags_t *tags;\r
+- * const char *tag;\r
+- *\r
+- * message = notmuch_database_find_message (database, message_id);\r
+- *\r
+- * for (tags = notmuch_message_get_tags (message);\r
+- * notmuch_tags_valid (tags);\r
+- * notmuch_result_move_to_next (tags))\r
+- * {\r
+- * tag = notmuch_tags_get (tags);\r
+- * ....\r
+- * }\r
+- *\r
+- * notmuch_message_destroy (message);\r
+- *\r
+- * Note that there's no explicit destructor needed for the\r
+- * notmuch_tags_t object. (For consistency, we do provide a\r
+- * notmuch_tags_destroy function, but there's no good reason to call\r
+- * it if the message is about to be destroyed).\r
+- */\r
+-func (self *Message) GetTags() *Tags {\r
+- if self.message == nil {\r
+- return nil\r
+- }\r
+- tags := C.notmuch_message_get_tags(self.message)\r
+- if tags == nil {\r
+- return nil\r
+- }\r
+- return &Tags{tags:tags}\r
+-}\r
+-\r
+-/* The longest possible tag value. */\r
+-const TAG_MAX = 200\r
+-\r
+-/* Add a tag to the given message.\r
+- *\r
+- * Return value:\r
+- *\r
+- * NOTMUCH_STATUS_SUCCESS: Tag successfully added to message\r
+- *\r
+- * NOTMUCH_STATUS_NULL_POINTER: The 'tag' argument is NULL\r
+- *\r
+- * NOTMUCH_STATUS_TAG_TOO_LONG: The length of 'tag' is too long\r
+- * (exceeds NOTMUCH_TAG_MAX)\r
+- *\r
+- * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
+- * mode so message cannot be modified.\r
+- */\r
+-func (self *Message) AddTag(tag string) Status {\r
+- if self.message == nil {\r
+- return STATUS_NULL_POINTER\r
+- }\r
+- c_tag := C.CString(tag)\r
+- defer C.free(unsafe.Pointer(c_tag))\r
+-\r
+- return Status(C.notmuch_message_add_tag(self.message, c_tag))\r
+-}\r
+-\r
+-/* Remove a tag from the given message.\r
+- *\r
+- * Return value:\r
+- *\r
+- * NOTMUCH_STATUS_SUCCESS: Tag successfully removed from message\r
+- *\r
+- * NOTMUCH_STATUS_NULL_POINTER: The 'tag' argument is NULL\r
+- *\r
+- * NOTMUCH_STATUS_TAG_TOO_LONG: The length of 'tag' is too long\r
+- * (exceeds NOTMUCH_TAG_MAX)\r
+- *\r
+- * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
+- * mode so message cannot be modified.\r
+- */\r
+-func (self *Message) RemoveTag(tag string) Status {\r
+- if self.message == nil {\r
+- return STATUS_NULL_POINTER\r
+- }\r
+- c_tag := C.CString(tag)\r
+- defer C.free(unsafe.Pointer(c_tag))\r
+-\r
+- return Status(C.notmuch_message_remove_tag(self.message, c_tag))\r
+-}\r
+-\r
+-/* Remove all tags from the given message.\r
+- *\r
+- * See notmuch_message_freeze for an example showing how to safely\r
+- * replace tag values.\r
+- *\r
+- * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
+- * mode so message cannot be modified.\r
+- */\r
+-func (self *Message) RemoveAllTags() Status {\r
+- if self.message == nil {\r
+- return STATUS_NULL_POINTER\r
+- }\r
+- return Status(C.notmuch_message_remove_all_tags(self.message))\r
+-}\r
+-\r
+-/* Freeze the current state of 'message' within the database.\r
+- *\r
+- * This means that changes to the message state, (via\r
+- * notmuch_message_add_tag, notmuch_message_remove_tag, and\r
+- * notmuch_message_remove_all_tags), will not be committed to the\r
+- * database until the message is thawed with notmuch_message_thaw.\r
+- *\r
+- * Multiple calls to freeze/thaw are valid and these calls will\r
+- * "stack". That is there must be as many calls to thaw as to freeze\r
+- * before a message is actually thawed.\r
+- *\r
+- * The ability to do freeze/thaw allows for safe transactions to\r
+- * change tag values. For example, explicitly setting a message to\r
+- * have a given set of tags might look like this:\r
+- *\r
+- * notmuch_message_freeze (message);\r
+- *\r
+- * notmuch_message_remove_all_tags (message);\r
+- *\r
+- * for (i = 0; i < NUM_TAGS; i++)\r
+- * notmuch_message_add_tag (message, tags[i]);\r
+- *\r
+- * notmuch_message_thaw (message);\r
+- *\r
+- * With freeze/thaw used like this, the message in the database is\r
+- * guaranteed to have either the full set of original tag values, or\r
+- * the full set of new tag values, but nothing in between.\r
+- *\r
+- * Imagine the example above without freeze/thaw and the operation\r
+- * somehow getting interrupted. This could result in the message being\r
+- * left with no tags if the interruption happened after\r
+- * notmuch_message_remove_all_tags but before notmuch_message_add_tag.\r
+- *\r
+- * Return value:\r
+- *\r
+- * NOTMUCH_STATUS_SUCCESS: Message successfully frozen.\r
+- *\r
+- * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
+- * mode so message cannot be modified.\r
+- */\r
+-func (self *Message) Freeze() Status {\r
+- if self.message == nil {\r
+- return STATUS_NULL_POINTER\r
+- }\r
+- return Status(C.notmuch_message_freeze(self.message))\r
+-}\r
+-\r
+-/* Thaw the current 'message', synchronizing any changes that may have\r
+- * occurred while 'message' was frozen into the notmuch database.\r
+- *\r
+- * See notmuch_message_freeze for an example of how to use this\r
+- * function to safely provide tag changes.\r
+- *\r
+- * Multiple calls to freeze/thaw are valid and these calls with\r
+- * "stack". That is there must be as many calls to thaw as to freeze\r
+- * before a message is actually thawed.\r
+- *\r
+- * Return value:\r
+- *\r
+- * NOTMUCH_STATUS_SUCCESS: Message successfully thawed, (or at least\r
+- * its frozen count has successfully been reduced by 1).\r
+- *\r
+- * NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: An attempt was made to thaw\r
+- * an unfrozen message. That is, there have been an unbalanced\r
+- * number of calls to notmuch_message_freeze and\r
+- * notmuch_message_thaw.\r
+- */\r
+-func (self *Message) Thaw() Status {\r
+- if self.message == nil {\r
+- return STATUS_NULL_POINTER\r
+- }\r
+-\r
+- return Status(C.notmuch_message_thaw(self.message))\r
+-}\r
+-\r
+-/* Destroy a notmuch_message_t object.\r
+- *\r
+- * It can be useful to call this function in the case of a single\r
+- * query object with many messages in the result, (such as iterating\r
+- * over the entire database). Otherwise, it's fine to never call this\r
+- * function and there will still be no memory leaks. (The memory from\r
+- * the messages get reclaimed when the containing query is destroyed.)\r
+- */\r
+-func (self *Message) Destroy() {\r
+- if self.message == nil {\r
+- return\r
+- }\r
+- C.notmuch_message_destroy(self.message)\r
+-}\r
+-\r
+-/* Is the given 'tags' iterator pointing at a valid tag.\r
+- *\r
+- * When this function returns TRUE, notmuch_tags_get will return a\r
+- * valid string. Whereas when this function returns FALSE,\r
+- * notmuch_tags_get will return NULL.\r
+- *\r
+- * See the documentation of notmuch_message_get_tags for example code\r
+- * showing how to iterate over a notmuch_tags_t object.\r
+- */\r
+-func (self *Tags) Valid() bool {\r
+- if self.tags == nil {\r
+- return false\r
+- }\r
+- v := C.notmuch_tags_valid(self.tags)\r
+- if v == 0 {\r
+- return false\r
+- }\r
+- return true\r
+-}\r
+-\r
+-/* Get the current tag from 'tags' as a string.\r
+- *\r
+- * Note: The returned string belongs to 'tags' and has a lifetime\r
+- * identical to it (and the query to which it ultimately belongs).\r
+- *\r
+- * See the documentation of notmuch_message_get_tags for example code\r
+- * showing how to iterate over a notmuch_tags_t object.\r
+- */\r
+-func (self *Tags) Get() string {\r
+- if self.tags == nil {\r
+- return ""\r
+- }\r
+- s := C.notmuch_tags_get(self.tags)\r
+- // we dont own 's'\r
+-\r
+- return C.GoString(s)\r
+-}\r
+-func (self *Tags) String() string {\r
+- return self.Get()\r
+-}\r
+-\r
+-/* Move the 'tags' iterator to the next tag.\r
+- *\r
+- * If 'tags' is already pointing at the last tag then the iterator\r
+- * will be moved to a point just beyond that last tag, (where\r
+- * notmuch_tags_valid will return FALSE and notmuch_tags_get will\r
+- * return NULL).\r
+- *\r
+- * See the documentation of notmuch_message_get_tags for example code\r
+- * showing how to iterate over a notmuch_tags_t object.\r
+- */\r
+-func (self *Tags) MoveToNext() {\r
+- if self.tags == nil {\r
+- return\r
+- }\r
+- C.notmuch_tags_move_to_next(self.tags)\r
+-}\r
+-\r
+-/* Destroy a notmuch_tags_t object.\r
+- *\r
+- * It's not strictly necessary to call this function. All memory from\r
+- * the notmuch_tags_t object will be reclaimed when the containing\r
+- * message or query objects are destroyed.\r
+- */\r
+-func (self *Tags) Destroy() {\r
+- if self.tags == nil {\r
+- return\r
+- }\r
+- C.notmuch_tags_destroy(self.tags)\r
+-}\r
+-\r
+-// TODO: wrap notmuch_directory_<fct>\r
+-\r
+-/* Destroy a notmuch_directory_t object. */\r
+-func (self *Directory) Destroy() {\r
+- if self.dir == nil {\r
+- return\r
+- }\r
+- C.notmuch_directory_destroy(self.dir)\r
+-}\r
+-\r
+-// TODO: wrap notmuch_filenames_<fct>\r
+-\r
+-/* Destroy a notmuch_filenames_t object.\r
+- *\r
+- * It's not strictly necessary to call this function. All memory from\r
+- * the notmuch_filenames_t object will be reclaimed when the\r
+- * containing directory object is destroyed.\r
+- *\r
+- * It is acceptable to pass NULL for 'filenames', in which case this\r
+- * function will do nothing.\r
+- */\r
+-func (self *Filenames) Destroy() {\r
+- if self.fnames == nil {\r
+- return\r
+- }\r
+- C.notmuch_filenames_destroy(self.fnames)\r
+-}\r
+-/* EOF */\r
+diff --git a/bindings/go/src/notmuch-addrlookup/addrlookup.go b/bindings/go/src/notmuch-addrlookup/addrlookup.go\r
+new file mode 100644\r
+index 0000000..03699fb\r
+--- /dev/null\r
++++ b/bindings/go/src/notmuch-addrlookup/addrlookup.go\r
+@@ -0,0 +1,263 @@\r
++package main\r
++\r
++// stdlib imports\r
++import "os"\r
++import "path"\r
++import "log"\r
++import "fmt"\r
++import "regexp"\r
++import "strings"\r
++import "sort"\r
++\r
++// 3rd-party imports\r
++import "notmuch"\r
++import "github.com/kless/goconfig/config"\r
++\r
++type mail_addr_freq struct {\r
++ addr string\r
++ count [3]uint\r
++}\r
++\r
++type frequencies map[string]uint\r
++\r
++/* Used to sort the email addresses from most to least used */\r
++func sort_by_freq(m1, m2 *mail_addr_freq) int {\r
++ if (m1.count[0] == m2.count[0] &&\r
++ m1.count[1] == m2.count[1] &&\r
++ m1.count[2] == m2.count[2]) {\r
++ return 0\r
++ }\r
++\r
++ if (m1.count[0] > m2.count[0] ||\r
++ m1.count[0] == m2.count[0] &&\r
++ m1.count[1] > m2.count[1] ||\r
++ m1.count[0] == m2.count[0] &&\r
++ m1.count[1] == m2.count[1] &&\r
++ m1.count[2] > m2.count[2]) {\r
++ return -1\r
++ }\r
++\r
++ return 1\r
++}\r
++\r
++type maddresses []*mail_addr_freq\r
++\r
++func (self *maddresses) Len() int {\r
++ return len(*self)\r
++}\r
++\r
++func (self *maddresses) Less(i,j int) bool {\r
++ m1 := (*self)[i]\r
++ m2 := (*self)[j]\r
++ v := sort_by_freq(m1, m2)\r
++ if v<=0 {\r
++ return true\r
++ }\r
++ return false\r
++}\r
++\r
++func (self *maddresses) Swap(i,j int) {\r
++ (*self)[i], (*self)[j] = (*self)[j], (*self)[i]\r
++}\r
++\r
++// find most frequent real name for each mail address\r
++func frequent_fullname(freqs frequencies) string {\r
++ var maxfreq uint = 0\r
++ fullname := ""\r
++ freqs_sz := len(freqs)\r
++\r
++ for mail,freq := range freqs {\r
++ if (freq > maxfreq && mail != "") || freqs_sz == 1 {\r
++ // only use the entry if it has a real name\r
++ // or if this is the only entry\r
++ maxfreq = freq\r
++ fullname = mail\r
++ }\r
++ }\r
++ return fullname\r
++}\r
++\r
++func addresses_by_frequency(msgs *notmuch.Messages, name string, pass uint, addr_to_realname *map[string]*frequencies) *frequencies {\r
++\r
++ freqs := make(frequencies)\r
++\r
++ pattern := `\s*(("(\.|[^"])*"|[^,])*<?(?mail\b\w+([-+.]\w+)*\@\w+[-\.\w]*\.([-\.\w]+)*\w\b)>?)`\r
++ // pattern := "\\s*((\\\"(\\\\.|[^\\\\\"])*\\\"|[^,])*" +\r
++ // "<?(?P<mail>\\b\\w+([-+.]\\w+)*\\@\\w+[-\\.\\w]*\\.([-\\.\\w]+)*\\w\\b)>?)"\r
++ pattern = `.*` + strings.ToLower(name) + `.*`\r
++ var re *regexp.Regexp = nil\r
++ var err os.Error = nil\r
++ if re,err = regexp.Compile(pattern); err != nil {\r
++ log.Printf("error: %v\n", err)\r
++ return &freqs\r
++ }\r
++ \r
++ headers := []string{"from"}\r
++ if pass == 1 {\r
++ headers = append(headers, "to", "cc", "bcc")\r
++ }\r
++\r
++ for ;msgs.Valid();msgs.MoveToNext() {\r
++ msg := msgs.Get()\r
++ //println("==> msg [", msg.GetMessageId(), "]")\r
++ for _,header := range headers {\r
++ froms := strings.ToLower(msg.GetHeader(header))\r
++ //println(" froms: ["+froms+"]")\r
++ for _,from := range strings.Split(froms, ",", -1) {\r
++ from = strings.Trim(from, " ")\r
++ match := re.FindString(from)\r
++ //println(" -> match: ["+match+"]")\r
++ occ,ok := freqs[match]\r
++ if !ok {\r
++ freqs[match] = 0\r
++ occ = 0\r
++ }\r
++ freqs[match] = occ+1\r
++ }\r
++ }\r
++ }\r
++ return &freqs\r
++}\r
++\r
++func search_address_passes(queries [3]*notmuch.Query, name string) []string {\r
++ var val []string\r
++ addr_freq := make(map[string]*mail_addr_freq)\r
++ addr_to_realname := make(map[string]*frequencies)\r
++\r
++ var pass uint = 0 // 0-based\r
++ for _,query := range queries {\r
++ if query == nil {\r
++ //println("**warning: idx [",idx,"] contains a nil query")\r
++ continue\r
++ }\r
++ msgs := query.SearchMessages()\r
++ ht := addresses_by_frequency(msgs, name, pass, &addr_to_realname)\r
++ for addr, count := range *ht {\r
++ freq,ok := addr_freq[addr]\r
++ if !ok {\r
++ freq = &mail_addr_freq{addr:addr, count:[3]uint{0,0,0}}\r
++ }\r
++ freq.count[pass] = count\r
++ addr_freq[addr] = freq\r
++ }\r
++ msgs.Destroy()\r
++ pass += 1\r
++ }\r
++\r
++ addrs := make(maddresses, len(addr_freq))\r
++ {\r
++ iaddr := 0\r
++ for _, freq := range addr_freq {\r
++ addrs[iaddr] = freq\r
++ iaddr += 1\r
++ }\r
++ }\r
++ sort.Sort(&addrs)\r
++\r
++ for _,addr := range addrs {\r
++ freqs,ok := addr_to_realname[addr.addr]\r
++ if ok {\r
++ val = append(val, frequent_fullname(*freqs))\r
++ } else {\r
++ val = append(val, addr.addr)\r
++ }\r
++ }\r
++ //println("val:",val)\r
++ return val\r
++}\r
++\r
++type address_matcher struct {\r
++ // the notmuch database\r
++ db *notmuch.Database\r
++ // full path of the notmuch database\r
++ user_db_path string\r
++ // user primary email\r
++ user_primary_email string\r
++ // user tag to mark from addresses as in the address book\r
++ user_addrbook_tag string\r
++}\r
++\r
++func new_address_matcher() *address_matcher {\r
++ var cfg *config.Config\r
++ var err os.Error\r
++\r
++ // honor NOTMUCH_CONFIG\r
++ home := os.Getenv("NOTMUCH_CONFIG")\r
++ if home == "" {\r
++ home = os.Getenv("HOME")\r
++ }\r
++\r
++ if cfg,err = config.ReadDefault(path.Join(home, ".notmuch-config")); err != nil {\r
++ log.Fatalf("error loading config file:",err)\r
++ }\r
++\r
++ db_path,_ := cfg.String("database", "path")\r
++ primary_email,_ := cfg.String("user", "primary_email")\r
++ addrbook_tag,err := cfg.String("user", "addrbook_tag")\r
++ if err != nil {\r
++ addrbook_tag = "addressbook"\r
++ }\r
++\r
++ self := &address_matcher{db:nil, \r
++ user_db_path:db_path,\r
++ user_primary_email:primary_email,\r
++ user_addrbook_tag:addrbook_tag}\r
++ return self\r
++}\r
++\r
++func (self *address_matcher) run(name string) {\r
++ queries := [3]*notmuch.Query{}\r
++ \r
++ // open the database\r
++ if db, status := notmuch.OpenDatabase(self.user_db_path,\r
++ notmuch.DATABASE_MODE_READ_ONLY); status == notmuch.STATUS_SUCCESS {\r
++ self.db = db\r
++ } else {\r
++ log.Fatalf("Failed to open the database: %v\n", status)\r
++ }\r
++\r
++ // pass 1: look at all from: addresses with the address book tag\r
++ query := "tag:" + self.user_addrbook_tag\r
++ if name != "" {\r
++ query = query + " and from:" + name + "*"\r
++ }\r
++ queries[0] = self.db.CreateQuery(query)\r
++\r
++ // pass 2: look at all to: addresses sent from our primary mail\r
++ query = ""\r
++ if name != "" {\r
++ query = "to:"+name+"*"\r
++ }\r
++ if self.user_primary_email != "" {\r
++ query = query + " from:" + self.user_primary_email\r
++ }\r
++ queries[1] = self.db.CreateQuery(query)\r
++\r
++ // if that leads only to a few hits, we check every from too\r
++ if queries[0].CountMessages() + queries[1].CountMessages() < 10 {\r
++ query = ""\r
++ if name != "" {\r
++ query = "from:"+name+"*"\r
++ }\r
++ queries[2] = self.db.CreateQuery(query)\r
++ }\r
++ \r
++ // actually retrieve and sort addresses\r
++ results := search_address_passes(queries, name)\r
++ for _,v := range results {\r
++ if v != "" && v != "\n" {\r
++ fmt.Println(v)\r
++ }\r
++ }\r
++ return\r
++}\r
++\r
++func main() {\r
++ //fmt.Println("args:",os.Args)\r
++ app := new_address_matcher()\r
++ name := ""\r
++ if len(os.Args) > 1 {\r
++ name = os.Args[1]\r
++ }\r
++ app.run(name)\r
++}\r
+\ No newline at end of file\r
+diff --git a/bindings/go/src/notmuch/notmuch.go b/bindings/go/src/notmuch/notmuch.go\r
+new file mode 100644\r
+index 0000000..8faf3bb\r
+--- /dev/null\r
++++ b/bindings/go/src/notmuch/notmuch.go\r
+@@ -0,0 +1,1125 @@\r
++// Wrapper around the notmuch library\r
++\r
++package notmuch\r
++\r
++/*\r
++#include <stdlib.h>\r
++#include <string.h>\r
++#include <time.h>\r
++#include "notmuch.h"\r
++*/\r
++import "C"\r
++import "unsafe"\r
++\r
++// Status codes used for the return values of most functions\r
++type Status C.notmuch_status_t\r
++const (\r
++ STATUS_SUCCESS Status = iota\r
++ STATUS_OUT_OF_MEMORY\r
++ STATUS_READ_ONLY_DATABASE\r
++ STATUS_XAPIAN_EXCEPTION\r
++ STATUS_FILE_ERROR\r
++ STATUS_FILE_NOT_EMAIL\r
++ STATUS_DUPLICATE_MESSAGE_ID\r
++ STATUS_NULL_POINTER\r
++ STATUS_TAG_TOO_LONG\r
++ STATUS_UNBALANCED_FREEZE_THAW\r
++ STATUS_UNBALANCED_ATOMIC\r
++\r
++ STATUS_LAST_STATUS\r
++)\r
++\r
++func (self Status) String() string {\r
++ var p *C.char\r
++ \r
++ // p is read-only\r
++ p = C.notmuch_status_to_string(C.notmuch_status_t(self))\r
++ if p != nil {\r
++ s := C.GoString(p)\r
++ return s\r
++ }\r
++ return ""\r
++}\r
++\r
++/* Various opaque data types. For each notmuch_<foo>_t see the various\r
++ * notmuch_<foo> functions below. */\r
++\r
++type Database struct {\r
++ db *C.notmuch_database_t\r
++}\r
++\r
++type Query struct {\r
++ query *C.notmuch_query_t\r
++}\r
++\r
++type Threads struct {\r
++ threads *C.notmuch_threads_t\r
++}\r
++\r
++type Thread struct {\r
++ thread *C.notmuch_thread_t\r
++}\r
++\r
++type Messages struct {\r
++ messages *C.notmuch_messages_t\r
++}\r
++\r
++type Message struct {\r
++ message *C.notmuch_message_t\r
++}\r
++\r
++type Tags struct {\r
++ tags *C.notmuch_tags_t\r
++}\r
++\r
++type Directory struct {\r
++ dir *C.notmuch_directory_t\r
++}\r
++\r
++type Filenames struct {\r
++ fnames *C.notmuch_filenames_t\r
++}\r
++\r
++type DatabaseMode C.notmuch_database_mode_t\r
++const (\r
++ DATABASE_MODE_READ_ONLY DatabaseMode = 0\r
++ DATABASE_MODE_READ_WRITE\r
++)\r
++\r
++// Create a new, empty notmuch database located at 'path'\r
++func NewDatabase(path string) (*Database, Status) {\r
++\r
++ var c_path *C.char = C.CString(path)\r
++ defer C.free(unsafe.Pointer(c_path))\r
++\r
++ if c_path == nil {\r
++ return nil, STATUS_OUT_OF_MEMORY\r
++ }\r
++\r
++ self := &Database{db:nil}\r
++ st := Status(C.notmuch_database_create(c_path, &self.db))\r
++ if st != STATUS_SUCCESS {\r
++ return nil, st\r
++ }\r
++ return self, st\r
++}\r
++\r
++/* Open an existing notmuch database located at 'path'.\r
++ *\r
++ * The database should have been created at some time in the past,\r
++ * (not necessarily by this process), by calling\r
++ * notmuch_database_create with 'path'. By default the database should be\r
++ * opened for reading only. In order to write to the database you need to\r
++ * pass the NOTMUCH_DATABASE_MODE_READ_WRITE mode.\r
++ *\r
++ * An existing notmuch database can be identified by the presence of a\r
++ * directory named ".notmuch" below 'path'.\r
++ *\r
++ * The caller should call notmuch_database_destroy when finished with\r
++ * this database.\r
++ *\r
++ * In case of any failure, this function returns NULL, (after printing\r
++ * an error message on stderr).\r
++ */\r
++func OpenDatabase(path string, mode DatabaseMode) (*Database, Status) {\r
++\r
++ var c_path *C.char = C.CString(path)\r
++ defer C.free(unsafe.Pointer(c_path))\r
++\r
++ if c_path == nil {\r
++ return nil, STATUS_OUT_OF_MEMORY\r
++ }\r
++\r
++ self := &Database{db:nil}\r
++ st := Status(C.notmuch_database_open(c_path, C.notmuch_database_mode_t(mode), &self.db))\r
++ if st != STATUS_SUCCESS {\r
++ return nil, st\r
++ }\r
++ return self, st\r
++}\r
++\r
++/* Close the given notmuch database, freeing all associated\r
++ * resources. See notmuch_database_open. */\r
++func (self *Database) Close() {\r
++ C.notmuch_database_destroy(self.db)\r
++}\r
++\r
++/* Return the database path of the given database.\r
++ */\r
++func (self *Database) GetPath() string {\r
++ \r
++ /* The return value is a string owned by notmuch so should not be\r
++ * modified nor freed by the caller. */\r
++ var p *C.char = C.notmuch_database_get_path(self.db)\r
++ if p != nil {\r
++ s := C.GoString(p)\r
++ return s\r
++ }\r
++ return ""\r
++}\r
++\r
++/* Return the database format version of the given database. */\r
++func (self *Database) GetVersion() uint {\r
++ return uint(C.notmuch_database_get_version(self.db))\r
++}\r
++\r
++/* Does this database need to be upgraded before writing to it?\r
++ *\r
++ * If this function returns TRUE then no functions that modify the\r
++ * database (notmuch_database_add_message, notmuch_message_add_tag,\r
++ * notmuch_directory_set_mtime, etc.) will work unless the function\r
++ * notmuch_database_upgrade is called successfully first. */\r
++func (self *Database) NeedsUpgrade() bool {\r
++ do_upgrade := C.notmuch_database_needs_upgrade(self.db)\r
++ if do_upgrade == 0 {\r
++ return false\r
++ }\r
++ return true\r
++}\r
++\r
++// TODO: notmuch_database_upgrade\r
++\r
++\r
++/* Retrieve a directory object from the database for 'path'.\r
++ *\r
++ * Here, 'path' should be a path relative to the path of 'database'\r
++ * (see notmuch_database_get_path), or else should be an absolute path\r
++ * with initial components that match the path of 'database'.\r
++ *\r
++ * Can return NULL if a Xapian exception occurs.\r
++ */\r
++func (self *Database) GetDirectory(path string) *Directory {\r
++ var c_path *C.char = C.CString(path)\r
++ defer C.free(unsafe.Pointer(c_path))\r
++\r
++ if c_path == nil {\r
++ return nil\r
++ }\r
++\r
++ c_dir := C.notmuch_database_get_directory(self.db, c_path)\r
++ if c_dir == nil {\r
++ return nil\r
++ }\r
++ return &Directory{dir:c_dir}\r
++}\r
++\r
++/* Add a new message to the given notmuch database.\r
++ *\r
++ * Here,'filename' should be a path relative to the path of\r
++ * 'database' (see notmuch_database_get_path), or else should be an\r
++ * absolute filename with initial components that match the path of\r
++ * 'database'.\r
++ *\r
++ * The file should be a single mail message (not a multi-message mbox)\r
++ * that is expected to remain at its current location, (since the\r
++ * notmuch database will reference the filename, and will not copy the\r
++ * entire contents of the file.\r
++ *\r
++ * If 'message' is not NULL, then, on successful return '*message'\r
++ * will be initialized to a message object that can be used for things\r
++ * such as adding tags to the just-added message. The user should call\r
++ * notmuch_message_destroy when done with the message. On any failure\r
++ * '*message' will be set to NULL.\r
++ *\r
++ * Return value:\r
++ *\r
++ * NOTMUCH_STATUS_SUCCESS: Message successfully added to database.\r
++ *\r
++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred,\r
++ * message not added.\r
++ *\r
++ * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: Message has the same message\r
++ * ID as another message already in the database. The new\r
++ * filename was successfully added to the message in the database\r
++ * (if not already present).\r
++ *\r
++ * NOTMUCH_STATUS_FILE_ERROR: an error occurred trying to open the\r
++ * file, (such as permission denied, or file not found,\r
++ * etc.). Nothing added to the database.\r
++ *\r
++ * NOTMUCH_STATUS_FILE_NOT_EMAIL: the contents of filename don't look\r
++ * like an email message. Nothing added to the database.\r
++ *\r
++ * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
++ * mode so no message can be added.\r
++ */\r
++func \r
++(self *Database) AddMessage(fname string) (*Message, Status) {\r
++ var c_fname *C.char = C.CString(fname)\r
++ defer C.free(unsafe.Pointer(c_fname))\r
++\r
++ if c_fname == nil {\r
++ return nil, STATUS_OUT_OF_MEMORY\r
++ }\r
++\r
++ var c_msg *C.notmuch_message_t = new(C.notmuch_message_t)\r
++ st := Status(C.notmuch_database_add_message(self.db, c_fname, &c_msg))\r
++\r
++ return &Message{message:c_msg}, st\r
++}\r
++\r
++/* Remove a message from the given notmuch database.\r
++ *\r
++ * Note that only this particular filename association is removed from\r
++ * the database. If the same message (as determined by the message ID)\r
++ * is still available via other filenames, then the message will\r
++ * persist in the database for those filenames. When the last filename\r
++ * is removed for a particular message, the database content for that\r
++ * message will be entirely removed.\r
++ *\r
++ * Return value:\r
++ *\r
++ * NOTMUCH_STATUS_SUCCESS: The last filename was removed and the\r
++ * message was removed from the database.\r
++ *\r
++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred,\r
++ * message not removed.\r
++ *\r
++ * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: This filename was removed but\r
++ * the message persists in the database with at least one other\r
++ * filename.\r
++ *\r
++ * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
++ * mode so no message can be removed.\r
++ */\r
++func (self *Database) RemoveMessage(fname string) Status {\r
++ \r
++ var c_fname *C.char = C.CString(fname)\r
++ defer C.free(unsafe.Pointer(c_fname))\r
++\r
++ if c_fname == nil {\r
++ return STATUS_OUT_OF_MEMORY\r
++ }\r
++\r
++ st := C.notmuch_database_remove_message(self.db, c_fname)\r
++ return Status(st)\r
++}\r
++\r
++/* Find a message with the given message_id.\r
++ *\r
++ * If the database contains a message with the given message_id, then\r
++ * a new notmuch_message_t object is returned. The caller should call\r
++ * notmuch_message_destroy when done with the message.\r
++ *\r
++ * This function returns NULL in the following situations:\r
++ *\r
++ * * No message is found with the given message_id\r
++ * * An out-of-memory situation occurs\r
++ * * A Xapian exception occurs\r
++ */\r
++func (self *Database) FindMessage(message_id string) (*Message, Status) {\r
++ \r
++ var c_msg_id *C.char = C.CString(message_id)\r
++ defer C.free(unsafe.Pointer(c_msg_id))\r
++\r
++ if c_msg_id == nil {\r
++ return nil, STATUS_OUT_OF_MEMORY\r
++ }\r
++\r
++ msg := &Message{message:nil}\r
++ st := Status(C.notmuch_database_find_message(self.db, c_msg_id, &msg.message))\r
++ if st != STATUS_SUCCESS {\r
++ return nil, st\r
++ }\r
++ return msg, st\r
++}\r
++\r
++/* Return a list of all tags found in the database.\r
++ *\r
++ * This function creates a list of all tags found in the database. The\r
++ * resulting list contains all tags from all messages found in the database.\r
++ *\r
++ * On error this function returns NULL.\r
++ */\r
++func (self *Database) GetAllTags() *Tags {\r
++ tags := C.notmuch_database_get_all_tags(self.db)\r
++ if tags == nil {\r
++ return nil\r
++ }\r
++ return &Tags{tags:tags}\r
++}\r
++\r
++/* Create a new query for 'database'.\r
++ *\r
++ * Here, 'database' should be an open database, (see\r
++ * notmuch_database_open and notmuch_database_create).\r
++ *\r
++ * For the query string, we'll document the syntax here more\r
++ * completely in the future, but it's likely to be a specialized\r
++ * version of the general Xapian query syntax:\r
++ *\r
++ * http://xapian.org/docs/queryparser.html\r
++ *\r
++ * As a special case, passing either a length-zero string, (that is ""),\r
++ * or a string consisting of a single asterisk (that is "*"), will\r
++ * result in a query that returns all messages in the database.\r
++ *\r
++ * See notmuch_query_set_sort for controlling the order of results.\r
++ * See notmuch_query_search_messages and notmuch_query_search_threads\r
++ * to actually execute the query.\r
++ *\r
++ * User should call notmuch_query_destroy when finished with this\r
++ * query.\r
++ *\r
++ * Will return NULL if insufficient memory is available.\r
++ */\r
++func (self *Database) CreateQuery(query string) *Query {\r
++ \r
++ var c_query *C.char = C.CString(query)\r
++ defer C.free(unsafe.Pointer(c_query))\r
++\r
++ if c_query == nil {\r
++ return nil\r
++ }\r
++\r
++ q := C.notmuch_query_create(self.db, c_query)\r
++ if q == nil {\r
++ return nil\r
++ }\r
++ return &Query{query:q}\r
++}\r
++\r
++/* Sort values for notmuch_query_set_sort */\r
++type Sort C.notmuch_sort_t\r
++const (\r
++ SORT_OLDEST_FIRST Sort = 0\r
++ SORT_NEWEST_FIRST\r
++ SORT_MESSAGE_ID\r
++ SORT_UNSORTED\r
++)\r
++\r
++/* Return the query_string of this query. See notmuch_query_create. */\r
++func (self *Query) String() string {\r
++ // FIXME: do we own 'q' or not ?\r
++ q := C.notmuch_query_get_query_string(self.query)\r
++ //defer C.free(unsafe.Pointer(q))\r
++ \r
++ if q != nil {\r
++ s := C.GoString(q)\r
++ return s\r
++ }\r
++\r
++ return ""\r
++}\r
++\r
++/* Specify the sorting desired for this query. */\r
++func (self *Query) SetSort(sort Sort) {\r
++ C.notmuch_query_set_sort(self.query, C.notmuch_sort_t(sort))\r
++}\r
++\r
++/* Return the sort specified for this query. See notmuch_query_set_sort. */\r
++func (self *Query) GetSort() Sort {\r
++ return Sort(C.notmuch_query_get_sort(self.query))\r
++}\r
++\r
++/* Execute a query for threads, returning a notmuch_threads_t object\r
++ * which can be used to iterate over the results. The returned threads\r
++ * object is owned by the query and as such, will only be valid until\r
++ * notmuch_query_destroy.\r
++ *\r
++ * Typical usage might be:\r
++ *\r
++ * notmuch_query_t *query;\r
++ * notmuch_threads_t *threads;\r
++ * notmuch_thread_t *thread;\r
++ *\r
++ * query = notmuch_query_create (database, query_string);\r
++ *\r
++ * for (threads = notmuch_query_search_threads (query);\r
++ * notmuch_threads_valid (threads);\r
++ * notmuch_threads_move_to_next (threads))\r
++ * {\r
++ * thread = notmuch_threads_get (threads);\r
++ * ....\r
++ * notmuch_thread_destroy (thread);\r
++ * }\r
++ *\r
++ * notmuch_query_destroy (query);\r
++ *\r
++ * Note: If you are finished with a thread before its containing\r
++ * query, you can call notmuch_thread_destroy to clean up some memory\r
++ * sooner (as in the above example). Otherwise, if your thread objects\r
++ * are long-lived, then you don't need to call notmuch_thread_destroy\r
++ * and all the memory will still be reclaimed when the query is\r
++ * destroyed.\r
++ *\r
++ * Note that there's no explicit destructor needed for the\r
++ * notmuch_threads_t object. (For consistency, we do provide a\r
++ * notmuch_threads_destroy function, but there's no good reason\r
++ * to call it if the query is about to be destroyed).\r
++ *\r
++ * If a Xapian exception occurs this function will return NULL.\r
++ */\r
++func (self *Query) SearchThreads() *Threads {\r
++ threads := C.notmuch_query_search_threads(self.query)\r
++ if threads == nil {\r
++ return nil\r
++ }\r
++ return &Threads{threads:threads}\r
++}\r
++\r
++/* Execute a query for messages, returning a notmuch_messages_t object\r
++ * which can be used to iterate over the results. The returned\r
++ * messages object is owned by the query and as such, will only be\r
++ * valid until notmuch_query_destroy.\r
++ *\r
++ * Typical usage might be:\r
++ *\r
++ * notmuch_query_t *query;\r
++ * notmuch_messages_t *messages;\r
++ * notmuch_message_t *message;\r
++ *\r
++ * query = notmuch_query_create (database, query_string);\r
++ *\r
++ * for (messages = notmuch_query_search_messages (query);\r
++ * notmuch_messages_valid (messages);\r
++ * notmuch_messages_move_to_next (messages))\r
++ * {\r
++ * message = notmuch_messages_get (messages);\r
++ * ....\r
++ * notmuch_message_destroy (message);\r
++ * }\r
++ *\r
++ * notmuch_query_destroy (query);\r
++ *\r
++ * Note: If you are finished with a message before its containing\r
++ * query, you can call notmuch_message_destroy to clean up some memory\r
++ * sooner (as in the above example). Otherwise, if your message\r
++ * objects are long-lived, then you don't need to call\r
++ * notmuch_message_destroy and all the memory will still be reclaimed\r
++ * when the query is destroyed.\r
++ *\r
++ * Note that there's no explicit destructor needed for the\r
++ * notmuch_messages_t object. (For consistency, we do provide a\r
++ * notmuch_messages_destroy function, but there's no good\r
++ * reason to call it if the query is about to be destroyed).\r
++ *\r
++ * If a Xapian exception occurs this function will return NULL.\r
++ */\r
++func (self *Query) SearchMessages() *Messages {\r
++ msgs := C.notmuch_query_search_messages(self.query)\r
++ if msgs == nil {\r
++ return nil\r
++ }\r
++ return &Messages{messages:msgs}\r
++}\r
++\r
++/* Destroy a notmuch_query_t along with any associated resources.\r
++ *\r
++ * This will in turn destroy any notmuch_threads_t and\r
++ * notmuch_messages_t objects generated by this query, (and in\r
++ * turn any notmuch_thread_t and notmuch_message_t objects generated\r
++ * from those results, etc.), if such objects haven't already been\r
++ * destroyed.\r
++ */\r
++func (self *Query) Destroy() {\r
++ if self.query != nil {\r
++ C.notmuch_query_destroy(self.query)\r
++ }\r
++}\r
++\r
++/* Return an estimate of the number of messages matching a search\r
++ *\r
++ * This function performs a search and returns Xapian's best\r
++ * guess as to number of matching messages.\r
++ *\r
++ * If a Xapian exception occurs, this function may return 0 (after\r
++ * printing a message).\r
++ */\r
++func (self *Query) CountMessages() uint {\r
++ return uint(C.notmuch_query_count_messages(self.query))\r
++}\r
++\r
++// TODO: wrap threads and thread\r
++\r
++/* Is the given 'threads' iterator pointing at a valid thread.\r
++ *\r
++ * When this function returns TRUE, notmuch_threads_get will return a\r
++ * valid object. Whereas when this function returns FALSE,\r
++ * notmuch_threads_get will return NULL.\r
++ *\r
++ * See the documentation of notmuch_query_search_threads for example\r
++ * code showing how to iterate over a notmuch_threads_t object.\r
++ */\r
++func (self *Threads) Valid() bool {\r
++ if self.threads == nil {\r
++ return false\r
++ }\r
++ valid := C.notmuch_threads_valid(self.threads)\r
++ if valid == 0 {\r
++ return false\r
++ }\r
++ return true\r
++}\r
++\r
++/* Destroy a notmuch_threads_t object.\r
++ *\r
++ * It's not strictly necessary to call this function. All memory from\r
++ * the notmuch_threads_t object will be reclaimed when the\r
++ * containg query object is destroyed.\r
++ */\r
++func (self *Threads) Destroy() {\r
++ if self.threads != nil {\r
++ C.notmuch_threads_destroy(self.threads)\r
++ }\r
++}\r
++\r
++/* Is the given 'messages' iterator pointing at a valid message.\r
++ *\r
++ * When this function returns TRUE, notmuch_messages_get will return a\r
++ * valid object. Whereas when this function returns FALSE,\r
++ * notmuch_messages_get will return NULL.\r
++ *\r
++ * See the documentation of notmuch_query_search_messages for example\r
++ * code showing how to iterate over a notmuch_messages_t object.\r
++ */\r
++func (self *Messages) Valid() bool {\r
++ if self.messages == nil {\r
++ return false\r
++ }\r
++ valid := C.notmuch_messages_valid(self.messages)\r
++ if valid == 0 {\r
++ return false\r
++ }\r
++ return true\r
++}\r
++\r
++/* Get the current message from 'messages' as a notmuch_message_t.\r
++ *\r
++ * Note: The returned message belongs to 'messages' and has a lifetime\r
++ * identical to it (and the query to which it belongs).\r
++ *\r
++ * See the documentation of notmuch_query_search_messages for example\r
++ * code showing how to iterate over a notmuch_messages_t object.\r
++ *\r
++ * If an out-of-memory situation occurs, this function will return\r
++ * NULL.\r
++ */\r
++func (self *Messages) Get() *Message {\r
++ if self.messages == nil {\r
++ return nil\r
++ }\r
++ msg := C.notmuch_messages_get(self.messages)\r
++ if msg == nil {\r
++ return nil\r
++ }\r
++ return &Message{message:msg}\r
++}\r
++\r
++/* Move the 'messages' iterator to the next message.\r
++ *\r
++ * If 'messages' is already pointing at the last message then the\r
++ * iterator will be moved to a point just beyond that last message,\r
++ * (where notmuch_messages_valid will return FALSE and\r
++ * notmuch_messages_get will return NULL).\r
++ *\r
++ * See the documentation of notmuch_query_search_messages for example\r
++ * code showing how to iterate over a notmuch_messages_t object.\r
++ */\r
++func (self *Messages) MoveToNext() {\r
++ if self.messages == nil {\r
++ return\r
++ }\r
++ C.notmuch_messages_move_to_next(self.messages)\r
++}\r
++\r
++/* Destroy a notmuch_messages_t object.\r
++ *\r
++ * It's not strictly necessary to call this function. All memory from\r
++ * the notmuch_messages_t object will be reclaimed when the containing\r
++ * query object is destroyed.\r
++ */\r
++func (self *Messages) Destroy() {\r
++ if self.messages != nil {\r
++ C.notmuch_messages_destroy(self.messages)\r
++ }\r
++}\r
++\r
++/* Return a list of tags from all messages.\r
++ *\r
++ * The resulting list is guaranteed not to contain duplicated tags.\r
++ *\r
++ * WARNING: You can no longer iterate over messages after calling this\r
++ * function, because the iterator will point at the end of the list.\r
++ * We do not have a function to reset the iterator yet and the only\r
++ * way how you can iterate over the list again is to recreate the\r
++ * message list.\r
++ *\r
++ * The function returns NULL on error.\r
++ */\r
++func (self *Messages) CollectTags() *Tags {\r
++ if self.messages == nil {\r
++ return nil\r
++ }\r
++ tags := C.notmuch_messages_collect_tags(self.messages)\r
++ if tags == nil {\r
++ return nil\r
++ }\r
++ return &Tags{tags:tags}\r
++}\r
++\r
++/* Get the message ID of 'message'.\r
++ *\r
++ * The returned string belongs to 'message' and as such, should not be\r
++ * modified by the caller and will only be valid for as long as the\r
++ * message is valid, (which is until the query from which it derived\r
++ * is destroyed).\r
++ *\r
++ * This function will not return NULL since Notmuch ensures that every\r
++ * message has a unique message ID, (Notmuch will generate an ID for a\r
++ * message if the original file does not contain one).\r
++ */\r
++func (self *Message) GetMessageId() string {\r
++\r
++ if self.message == nil {\r
++ return ""\r
++ }\r
++ id := C.notmuch_message_get_message_id(self.message)\r
++ // we dont own id\r
++ // defer C.free(unsafe.Pointer(id))\r
++ if id == nil {\r
++ return ""\r
++ }\r
++ return C.GoString(id)\r
++}\r
++\r
++/* Get the thread ID of 'message'.\r
++ *\r
++ * The returned string belongs to 'message' and as such, should not be\r
++ * modified by the caller and will only be valid for as long as the\r
++ * message is valid, (for example, until the user calls\r
++ * notmuch_message_destroy on 'message' or until a query from which it\r
++ * derived is destroyed).\r
++ *\r
++ * This function will not return NULL since Notmuch ensures that every\r
++ * message belongs to a single thread.\r
++ */\r
++func (self *Message) GetThreadId() string {\r
++ \r
++ if self.message == nil {\r
++ return ""\r
++ }\r
++ id := C.notmuch_message_get_thread_id(self.message)\r
++ // we dont own id\r
++ // defer C.free(unsafe.Pointer(id))\r
++ \r
++ if id == nil {\r
++ return ""\r
++ }\r
++\r
++ return C.GoString(id)\r
++}\r
++\r
++/* Get a notmuch_messages_t iterator for all of the replies to\r
++ * 'message'.\r
++ *\r
++ * Note: This call only makes sense if 'message' was ultimately\r
++ * obtained from a notmuch_thread_t object, (such as by coming\r
++ * directly from the result of calling notmuch_thread_get_\r
++ * toplevel_messages or by any number of subsequent\r
++ * calls to notmuch_message_get_replies).\r
++ *\r
++ * If 'message' was obtained through some non-thread means, (such as\r
++ * by a call to notmuch_query_search_messages), then this function\r
++ * will return NULL.\r
++ *\r
++ * If there are no replies to 'message', this function will return\r
++ * NULL. (Note that notmuch_messages_valid will accept that NULL\r
++ * value as legitimate, and simply return FALSE for it.)\r
++ */\r
++func (self *Message) GetReplies() *Messages {\r
++ if self.message == nil {\r
++ return nil\r
++ }\r
++ msgs := C.notmuch_message_get_replies(self.message)\r
++ if msgs == nil {\r
++ return nil\r
++ }\r
++ return &Messages{messages:msgs}\r
++}\r
++\r
++/* Get a filename for the email corresponding to 'message'.\r
++ *\r
++ * The returned filename is an absolute filename, (the initial\r
++ * component will match notmuch_database_get_path() ).\r
++ *\r
++ * The returned string belongs to the message so should not be\r
++ * modified or freed by the caller (nor should it be referenced after\r
++ * the message is destroyed).\r
++ *\r
++ * Note: If this message corresponds to multiple files in the mail\r
++ * store, (that is, multiple files contain identical message IDs),\r
++ * this function will arbitrarily return a single one of those\r
++ * filenames.\r
++ */\r
++func (self *Message) GetFileName() string {\r
++ if self.message == nil {\r
++ return ""\r
++ }\r
++ fname := C.notmuch_message_get_filename(self.message)\r
++ // we dont own fname\r
++ // defer C.free(unsafe.Pointer(fname))\r
++ \r
++ if fname == nil {\r
++ return ""\r
++ }\r
++\r
++ return C.GoString(fname)\r
++}\r
++\r
++type Flag C.notmuch_message_flag_t\r
++const (\r
++ MESSAGE_FLAG_MATCH Flag = 0\r
++)\r
++\r
++/* Get a value of a flag for the email corresponding to 'message'. */\r
++func (self *Message) GetFlag(flag Flag) bool {\r
++ if self.message == nil {\r
++ return false\r
++ }\r
++ v := C.notmuch_message_get_flag(self.message, C.notmuch_message_flag_t(flag))\r
++ if v == 0 {\r
++ return false\r
++ }\r
++ return true\r
++}\r
++\r
++/* Set a value of a flag for the email corresponding to 'message'. */\r
++func (self *Message) SetFlag(flag Flag, value bool) {\r
++ if self.message == nil {\r
++ return\r
++ }\r
++ var v C.notmuch_bool_t = 0\r
++ if value {\r
++ v = 1\r
++ }\r
++ C.notmuch_message_set_flag(self.message, C.notmuch_message_flag_t(flag), v)\r
++}\r
++\r
++// TODO: wrap notmuch_message_get_date\r
++\r
++/* Get the value of the specified header from 'message'.\r
++ *\r
++ * The value will be read from the actual message file, not from the\r
++ * notmuch database. The header name is case insensitive.\r
++ *\r
++ * The returned string belongs to the message so should not be\r
++ * modified or freed by the caller (nor should it be referenced after\r
++ * the message is destroyed).\r
++ *\r
++ * Returns an empty string ("") if the message does not contain a\r
++ * header line matching 'header'. Returns NULL if any error occurs.\r
++ */\r
++func (self *Message) GetHeader(header string) string {\r
++ if self.message == nil {\r
++ return ""\r
++ }\r
++ \r
++ var c_header *C.char = C.CString(header)\r
++ defer C.free(unsafe.Pointer(c_header))\r
++ \r
++ /* we dont own value */\r
++ value := C.notmuch_message_get_header(self.message, c_header)\r
++ if value == nil {\r
++ return ""\r
++ }\r
++ \r
++ return C.GoString(value)\r
++}\r
++\r
++/* Get the tags for 'message', returning a notmuch_tags_t object which\r
++ * can be used to iterate over all tags.\r
++ *\r
++ * The tags object is owned by the message and as such, will only be\r
++ * valid for as long as the message is valid, (which is until the\r
++ * query from which it derived is destroyed).\r
++ *\r
++ * Typical usage might be:\r
++ *\r
++ * notmuch_message_t *message;\r
++ * notmuch_tags_t *tags;\r
++ * const char *tag;\r
++ *\r
++ * message = notmuch_database_find_message (database, message_id);\r
++ *\r
++ * for (tags = notmuch_message_get_tags (message);\r
++ * notmuch_tags_valid (tags);\r
++ * notmuch_result_move_to_next (tags))\r
++ * {\r
++ * tag = notmuch_tags_get (tags);\r
++ * ....\r
++ * }\r
++ *\r
++ * notmuch_message_destroy (message);\r
++ *\r
++ * Note that there's no explicit destructor needed for the\r
++ * notmuch_tags_t object. (For consistency, we do provide a\r
++ * notmuch_tags_destroy function, but there's no good reason to call\r
++ * it if the message is about to be destroyed).\r
++ */\r
++func (self *Message) GetTags() *Tags {\r
++ if self.message == nil {\r
++ return nil\r
++ }\r
++ tags := C.notmuch_message_get_tags(self.message)\r
++ if tags == nil {\r
++ return nil\r
++ }\r
++ return &Tags{tags:tags}\r
++}\r
++\r
++/* The longest possible tag value. */\r
++const TAG_MAX = 200\r
++\r
++/* Add a tag to the given message.\r
++ *\r
++ * Return value:\r
++ *\r
++ * NOTMUCH_STATUS_SUCCESS: Tag successfully added to message\r
++ *\r
++ * NOTMUCH_STATUS_NULL_POINTER: The 'tag' argument is NULL\r
++ *\r
++ * NOTMUCH_STATUS_TAG_TOO_LONG: The length of 'tag' is too long\r
++ * (exceeds NOTMUCH_TAG_MAX)\r
++ *\r
++ * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
++ * mode so message cannot be modified.\r
++ */\r
++func (self *Message) AddTag(tag string) Status {\r
++ if self.message == nil {\r
++ return STATUS_NULL_POINTER\r
++ }\r
++ c_tag := C.CString(tag)\r
++ defer C.free(unsafe.Pointer(c_tag))\r
++\r
++ return Status(C.notmuch_message_add_tag(self.message, c_tag))\r
++}\r
++\r
++/* Remove a tag from the given message.\r
++ *\r
++ * Return value:\r
++ *\r
++ * NOTMUCH_STATUS_SUCCESS: Tag successfully removed from message\r
++ *\r
++ * NOTMUCH_STATUS_NULL_POINTER: The 'tag' argument is NULL\r
++ *\r
++ * NOTMUCH_STATUS_TAG_TOO_LONG: The length of 'tag' is too long\r
++ * (exceeds NOTMUCH_TAG_MAX)\r
++ *\r
++ * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
++ * mode so message cannot be modified.\r
++ */\r
++func (self *Message) RemoveTag(tag string) Status {\r
++ if self.message == nil {\r
++ return STATUS_NULL_POINTER\r
++ }\r
++ c_tag := C.CString(tag)\r
++ defer C.free(unsafe.Pointer(c_tag))\r
++\r
++ return Status(C.notmuch_message_remove_tag(self.message, c_tag))\r
++}\r
++\r
++/* Remove all tags from the given message.\r
++ *\r
++ * See notmuch_message_freeze for an example showing how to safely\r
++ * replace tag values.\r
++ *\r
++ * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
++ * mode so message cannot be modified.\r
++ */\r
++func (self *Message) RemoveAllTags() Status {\r
++ if self.message == nil {\r
++ return STATUS_NULL_POINTER\r
++ }\r
++ return Status(C.notmuch_message_remove_all_tags(self.message))\r
++}\r
++\r
++/* Freeze the current state of 'message' within the database.\r
++ *\r
++ * This means that changes to the message state, (via\r
++ * notmuch_message_add_tag, notmuch_message_remove_tag, and\r
++ * notmuch_message_remove_all_tags), will not be committed to the\r
++ * database until the message is thawed with notmuch_message_thaw.\r
++ *\r
++ * Multiple calls to freeze/thaw are valid and these calls will\r
++ * "stack". That is there must be as many calls to thaw as to freeze\r
++ * before a message is actually thawed.\r
++ *\r
++ * The ability to do freeze/thaw allows for safe transactions to\r
++ * change tag values. For example, explicitly setting a message to\r
++ * have a given set of tags might look like this:\r
++ *\r
++ * notmuch_message_freeze (message);\r
++ *\r
++ * notmuch_message_remove_all_tags (message);\r
++ *\r
++ * for (i = 0; i < NUM_TAGS; i++)\r
++ * notmuch_message_add_tag (message, tags[i]);\r
++ *\r
++ * notmuch_message_thaw (message);\r
++ *\r
++ * With freeze/thaw used like this, the message in the database is\r
++ * guaranteed to have either the full set of original tag values, or\r
++ * the full set of new tag values, but nothing in between.\r
++ *\r
++ * Imagine the example above without freeze/thaw and the operation\r
++ * somehow getting interrupted. This could result in the message being\r
++ * left with no tags if the interruption happened after\r
++ * notmuch_message_remove_all_tags but before notmuch_message_add_tag.\r
++ *\r
++ * Return value:\r
++ *\r
++ * NOTMUCH_STATUS_SUCCESS: Message successfully frozen.\r
++ *\r
++ * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only\r
++ * mode so message cannot be modified.\r
++ */\r
++func (self *Message) Freeze() Status {\r
++ if self.message == nil {\r
++ return STATUS_NULL_POINTER\r
++ }\r
++ return Status(C.notmuch_message_freeze(self.message))\r
++}\r
++\r
++/* Thaw the current 'message', synchronizing any changes that may have\r
++ * occurred while 'message' was frozen into the notmuch database.\r
++ *\r
++ * See notmuch_message_freeze for an example of how to use this\r
++ * function to safely provide tag changes.\r
++ *\r
++ * Multiple calls to freeze/thaw are valid and these calls with\r
++ * "stack". That is there must be as many calls to thaw as to freeze\r
++ * before a message is actually thawed.\r
++ *\r
++ * Return value:\r
++ *\r
++ * NOTMUCH_STATUS_SUCCESS: Message successfully thawed, (or at least\r
++ * its frozen count has successfully been reduced by 1).\r
++ *\r
++ * NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: An attempt was made to thaw\r
++ * an unfrozen message. That is, there have been an unbalanced\r
++ * number of calls to notmuch_message_freeze and\r
++ * notmuch_message_thaw.\r
++ */\r
++func (self *Message) Thaw() Status {\r
++ if self.message == nil {\r
++ return STATUS_NULL_POINTER\r
++ }\r
++\r
++ return Status(C.notmuch_message_thaw(self.message))\r
++}\r
++\r
++/* Destroy a notmuch_message_t object.\r
++ *\r
++ * It can be useful to call this function in the case of a single\r
++ * query object with many messages in the result, (such as iterating\r
++ * over the entire database). Otherwise, it's fine to never call this\r
++ * function and there will still be no memory leaks. (The memory from\r
++ * the messages get reclaimed when the containing query is destroyed.)\r
++ */\r
++func (self *Message) Destroy() {\r
++ if self.message == nil {\r
++ return\r
++ }\r
++ C.notmuch_message_destroy(self.message)\r
++}\r
++\r
++/* Is the given 'tags' iterator pointing at a valid tag.\r
++ *\r
++ * When this function returns TRUE, notmuch_tags_get will return a\r
++ * valid string. Whereas when this function returns FALSE,\r
++ * notmuch_tags_get will return NULL.\r
++ *\r
++ * See the documentation of notmuch_message_get_tags for example code\r
++ * showing how to iterate over a notmuch_tags_t object.\r
++ */\r
++func (self *Tags) Valid() bool {\r
++ if self.tags == nil {\r
++ return false\r
++ }\r
++ v := C.notmuch_tags_valid(self.tags)\r
++ if v == 0 {\r
++ return false\r
++ }\r
++ return true\r
++}\r
++\r
++/* Get the current tag from 'tags' as a string.\r
++ *\r
++ * Note: The returned string belongs to 'tags' and has a lifetime\r
++ * identical to it (and the query to which it ultimately belongs).\r
++ *\r
++ * See the documentation of notmuch_message_get_tags for example code\r
++ * showing how to iterate over a notmuch_tags_t object.\r
++ */\r
++func (self *Tags) Get() string {\r
++ if self.tags == nil {\r
++ return ""\r
++ }\r
++ s := C.notmuch_tags_get(self.tags)\r
++ // we dont own 's'\r
++\r
++ return C.GoString(s)\r
++}\r
++func (self *Tags) String() string {\r
++ return self.Get()\r
++}\r
++\r
++/* Move the 'tags' iterator to the next tag.\r
++ *\r
++ * If 'tags' is already pointing at the last tag then the iterator\r
++ * will be moved to a point just beyond that last tag, (where\r
++ * notmuch_tags_valid will return FALSE and notmuch_tags_get will\r
++ * return NULL).\r
++ *\r
++ * See the documentation of notmuch_message_get_tags for example code\r
++ * showing how to iterate over a notmuch_tags_t object.\r
++ */\r
++func (self *Tags) MoveToNext() {\r
++ if self.tags == nil {\r
++ return\r
++ }\r
++ C.notmuch_tags_move_to_next(self.tags)\r
++}\r
++\r
++/* Destroy a notmuch_tags_t object.\r
++ *\r
++ * It's not strictly necessary to call this function. All memory from\r
++ * the notmuch_tags_t object will be reclaimed when the containing\r
++ * message or query objects are destroyed.\r
++ */\r
++func (self *Tags) Destroy() {\r
++ if self.tags == nil {\r
++ return\r
++ }\r
++ C.notmuch_tags_destroy(self.tags)\r
++}\r
++\r
++// TODO: wrap notmuch_directory_<fct>\r
++\r
++/* Destroy a notmuch_directory_t object. */\r
++func (self *Directory) Destroy() {\r
++ if self.dir == nil {\r
++ return\r
++ }\r
++ C.notmuch_directory_destroy(self.dir)\r
++}\r
++\r
++// TODO: wrap notmuch_filenames_<fct>\r
++\r
++/* Destroy a notmuch_filenames_t object.\r
++ *\r
++ * It's not strictly necessary to call this function. All memory from\r
++ * the notmuch_filenames_t object will be reclaimed when the\r
++ * containing directory object is destroyed.\r
++ *\r
++ * It is acceptable to pass NULL for 'filenames', in which case this\r
++ * function will do nothing.\r
++ */\r
++func (self *Filenames) Destroy() {\r
++ if self.fnames == nil {\r
++ return\r
++ }\r
++ C.notmuch_filenames_destroy(self.fnames)\r
++}\r
++/* EOF */\r
+-- \r
+1.7.10\r
+\r