[PATCH 1/5] go: reorganize the go bindings
go 1 introduced the "go" program that simplifies building of libraries and programs. This patch reorganizes the go code so it can be compiled using the new utility, it does not change any files. Signed-off-by: Justus Winter <4winter at informatik.uni-hamburg.de> --- bindings/go/cmds/notmuch-addrlookup.go | 263 - bindings/go/pkg/notmuch.go | 1125 -- bindings/go/src/notmuch-addrlookup/addrlookup.go | 263 + bindings/go/src/notmuch/notmuch.go | 1125 ++ 4 files changed, 1388 insertions(+), 1388 deletions(-) delete mode 100644 bindings/go/cmds/notmuch-addrlookup.go delete mode 100644 bindings/go/pkg/notmuch.go create mode 100644 bindings/go/src/notmuch-addrlookup/addrlookup.go create mode 100644 bindings/go/src/notmuch/notmuch.go diff --git a/bindings/go/cmds/notmuch-addrlookup.go b/bindings/go/cmds/notmuch-addrlookup.go deleted file mode 100644 index 03699fb..000 --- a/bindings/go/cmds/notmuch-addrlookup.go +++ /dev/null @@ -1,263 +0,0 @@ -package main - -// stdlib imports -import "os" -import "path" -import "log" -import "fmt" -import "regexp" -import "strings" -import "sort" - -// 3rd-party imports -import "notmuch" -import "github.com/kless/goconfig/config" - -type mail_addr_freq struct { - addr string - count [3]uint -} - -type frequencies map[string]uint - -/* Used to sort the email addresses from most to least used */ -func sort_by_freq(m1, m2 *mail_addr_freq) int { - if (m1.count[0] == m2.count[0] && - m1.count[1] == m2.count[1] && - m1.count[2] == m2.count[2]) { - return 0 - } - - if (m1.count[0] > m2.count[0] || - m1.count[0] == m2.count[0] && - m1.count[1] > m2.count[1] || - m1.count[0] == m2.count[0] && - m1.count[1] == m2.count[1] && - m1.count[2] > m2.count[2]) { - return -1 - } - - return 1 -} - -type maddresses []*mail_addr_freq - -func (self *maddresses) Len() int { - return len(*self) -} - -func (self *maddresses) Less(i,j int) bool { - m1 := (*self)[i] - m2 := (*self)[j] - v := sort_by_freq(m1, m2) - if v<=0 { - return true - } - return false -} - -func (self *maddresses) Swap(i,j int) { - (*self)[i], (*self)[j] = (*self)[j], (*self)[i] -} - -// find most frequent real name for each mail address -func frequent_fullname(freqs frequencies) string { - var maxfreq uint = 0 - fullname := "" - freqs_sz := len(freqs) - - for mail,freq := range freqs { - if (freq > maxfreq && mail != "") || freqs_sz == 1 { - // only use the entry if it has a real name - // or if this is the only entry - maxfreq = freq - fullname = mail - } - } - return fullname -} - -func addresses_by_frequency(msgs *notmuch.Messages, name string, pass uint, addr_to_realname *map[string]*frequencies) *frequencies { - - freqs := make(frequencies) - - pattern := `\s*(("(\.|[^"])*"|[^,])*?)` - // pattern := "\\s*((\\\"(.|[^\"])*\\\"|[^,])*" + - // "\\b\\w+([-+.]\\w+)*\\@\\w+[-\\.\\w]*\\.([-\\.\\w]+)*\\w\\b)>?)" - pattern = `.*` + strings.ToLower(name) + `.*` - var re *regexp.Regexp = nil - var err os.Error = nil - if re,err = regexp.Compile(pattern); err != nil { - log.Printf("error: %v\n", err) - return - } - - headers := []string{"from"} - if pass == 1 { - headers = append(headers, "to", "cc", "bcc") - } - - for ;msgs.Valid();msgs.MoveToNext() { - msg := msgs.Get() - //println("==> msg [", msg.GetMessageId(), "]") - for _,header := range headers { - froms := strings.ToLower(msg.GetHeader(header)) - //println(" froms: ["+froms+"]") - for _,from := range strings.Split(froms, ",", -1) { - from = strings.Trim(from, " ") - match := re.FindString(from) - //println(" -> match: ["+match+"]") - occ,ok := freqs[match] - if !ok { - freqs[match] = 0 - occ = 0 - } - freqs[match] = occ+1 - } - } - } - return -} - -func search_address_passes(queries [3]*notmuch.Query, name string) []string { - var val []string - addr_freq := make(map[string]*mail_addr_freq) - addr_to_realname := make(map[string]*frequencies) - - var pass uint = 0 // 0-based - for
[PATCH 1/5] go: reorganize the go bindings
Quoting Austin Clements (2012-05-04 20:43:20) > Quoth myself on May 04 at 2:38 pm: > > Quoth Justus Winter on Apr 30 at 9:55 pm: > > > Signed-off-by: Justus Winter <4winter at informatik.uni-hamburg.de> > > > > Whole series LGTM (and yay gofmt!). I have only two minor comments. > > > > It would be nice to have a little more log message for some of these. > > Mostly the first one could use some explanation of why you're > > rearranging the source tree and a mention that there are no changes to > > the files (since this is hard to get from the diff). Good point. > > It would also be nice if this could optionally be built using the > > libnotmuch and notmuch.h directly from the source tree containing the > > Go bindings, rather than requiring them to be installed system-wide. > > I don't know Go 1's build system well enough to know if there's an > > easy way to do this. Yes, I've been pondering that myself. There are CGO_CFLAGS and CGO_LDFLAGS that could be used to point the c compiler to the right paths. I'll experiment with this and propose a patch. > Oh, also a news patch would be good, though that can obviously be > separate. Sure. I'll send an updated patch series. Thanks for the review. Justus
Re: [PATCH 1/5] go: reorganize the go bindings
Quoting Austin Clements (2012-05-04 20:43:20) Quoth myself on May 04 at 2:38 pm: Quoth Justus Winter on Apr 30 at 9:55 pm: Signed-off-by: Justus Winter 4win...@informatik.uni-hamburg.de Whole series LGTM (and yay gofmt!). I have only two minor comments. It would be nice to have a little more log message for some of these. Mostly the first one could use some explanation of why you're rearranging the source tree and a mention that there are no changes to the files (since this is hard to get from the diff). Good point. It would also be nice if this could optionally be built using the libnotmuch and notmuch.h directly from the source tree containing the Go bindings, rather than requiring them to be installed system-wide. I don't know Go 1's build system well enough to know if there's an easy way to do this. Yes, I've been pondering that myself. There are CGO_CFLAGS and CGO_LDFLAGS that could be used to point the c compiler to the right paths. I'll experiment with this and propose a patch. Oh, also a news patch would be good, though that can obviously be separate. Sure. I'll send an updated patch series. Thanks for the review. Justus ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH 1/5] go: reorganize the go bindings
Quoth myself on May 04 at 2:38 pm: > Quoth Justus Winter on Apr 30 at 9:55 pm: > > Signed-off-by: Justus Winter <4winter at informatik.uni-hamburg.de> > > Whole series LGTM (and yay gofmt!). I have only two minor comments. > > It would be nice to have a little more log message for some of these. > Mostly the first one could use some explanation of why you're > rearranging the source tree and a mention that there are no changes to > the files (since this is hard to get from the diff). > > It would also be nice if this could optionally be built using the > libnotmuch and notmuch.h directly from the source tree containing the > Go bindings, rather than requiring them to be installed system-wide. > I don't know Go 1's build system well enough to know if there's an > easy way to do this. Oh, also a news patch would be good, though that can obviously be separate.
[PATCH 1/5] go: reorganize the go bindings
Quoth Justus Winter on Apr 30 at 9:55 pm: > Signed-off-by: Justus Winter <4winter at informatik.uni-hamburg.de> Whole series LGTM (and yay gofmt!). I have only two minor comments. It would be nice to have a little more log message for some of these. Mostly the first one could use some explanation of why you're rearranging the source tree and a mention that there are no changes to the files (since this is hard to get from the diff). It would also be nice if this could optionally be built using the libnotmuch and notmuch.h directly from the source tree containing the Go bindings, rather than requiring them to be installed system-wide. I don't know Go 1's build system well enough to know if there's an easy way to do this.
Re: [PATCH 1/5] go: reorganize the go bindings
Quoth Justus Winter on Apr 30 at 9:55 pm: Signed-off-by: Justus Winter 4win...@informatik.uni-hamburg.de Whole series LGTM (and yay gofmt!). I have only two minor comments. It would be nice to have a little more log message for some of these. Mostly the first one could use some explanation of why you're rearranging the source tree and a mention that there are no changes to the files (since this is hard to get from the diff). It would also be nice if this could optionally be built using the libnotmuch and notmuch.h directly from the source tree containing the Go bindings, rather than requiring them to be installed system-wide. I don't know Go 1's build system well enough to know if there's an easy way to do this. ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
Re: [PATCH 1/5] go: reorganize the go bindings
Quoth myself on May 04 at 2:38 pm: Quoth Justus Winter on Apr 30 at 9:55 pm: Signed-off-by: Justus Winter 4win...@informatik.uni-hamburg.de Whole series LGTM (and yay gofmt!). I have only two minor comments. It would be nice to have a little more log message for some of these. Mostly the first one could use some explanation of why you're rearranging the source tree and a mention that there are no changes to the files (since this is hard to get from the diff). It would also be nice if this could optionally be built using the libnotmuch and notmuch.h directly from the source tree containing the Go bindings, rather than requiring them to be installed system-wide. I don't know Go 1's build system well enough to know if there's an easy way to do this. Oh, also a news patch would be good, though that can obviously be separate. ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH 1/5] go: reorganize the go bindings
Signed-off-by: Justus Winter <4winter at informatik.uni-hamburg.de> --- bindings/go/cmds/notmuch-addrlookup.go | 259 - bindings/go/pkg/notmuch.go | 1124 -- bindings/go/src/notmuch-addrlookup/addrlookup.go | 259 + bindings/go/src/notmuch/notmuch.go | 1124 ++ 4 files changed, 1383 insertions(+), 1383 deletions(-) delete mode 100644 bindings/go/cmds/notmuch-addrlookup.go delete mode 100644 bindings/go/pkg/notmuch.go create mode 100644 bindings/go/src/notmuch-addrlookup/addrlookup.go create mode 100644 bindings/go/src/notmuch/notmuch.go diff --git a/bindings/go/cmds/notmuch-addrlookup.go b/bindings/go/cmds/notmuch-addrlookup.go deleted file mode 100644 index 16958e5..000 --- a/bindings/go/cmds/notmuch-addrlookup.go +++ /dev/null @@ -1,259 +0,0 @@ -package main - -// stdlib imports -import "os" -import "path" -import "log" -import "fmt" -import "regexp" -import "strings" -import "sort" - -// 3rd-party imports -import "notmuch" -import "github.com/kless/goconfig/config" - -type mail_addr_freq struct { - addr string - count [3]uint -} - -type frequencies map[string]uint - -/* Used to sort the email addresses from most to least used */ -func sort_by_freq(m1, m2 *mail_addr_freq) int { - if (m1.count[0] == m2.count[0] && - m1.count[1] == m2.count[1] && - m1.count[2] == m2.count[2]) { - return 0 - } - - if (m1.count[0] > m2.count[0] || - m1.count[0] == m2.count[0] && - m1.count[1] > m2.count[1] || - m1.count[0] == m2.count[0] && - m1.count[1] == m2.count[1] && - m1.count[2] > m2.count[2]) { - return -1 - } - - return 1 -} - -type maddresses []*mail_addr_freq - -func (self *maddresses) Len() int { - return len(*self) -} - -func (self *maddresses) Less(i,j int) bool { - m1 := (*self)[i] - m2 := (*self)[j] - v := sort_by_freq(m1, m2) - if v<=0 { - return true - } - return false -} - -func (self *maddresses) Swap(i,j int) { - (*self)[i], (*self)[j] = (*self)[j], (*self)[i] -} - -// find most frequent real name for each mail address -func frequent_fullname(freqs frequencies) string { - var maxfreq uint = 0 - fullname := "" - freqs_sz := len(freqs) - - for mail,freq := range freqs { - if (freq > maxfreq && mail != "") || freqs_sz == 1 { - // only use the entry if it has a real name - // or if this is the only entry - maxfreq = freq - fullname = mail - } - } - return fullname -} - -func addresses_by_frequency(msgs *notmuch.Messages, name string, pass uint, addr_to_realname *map[string]*frequencies) *frequencies { - - freqs := make(frequencies) - - pattern := `\s*(("(\.|[^"])*"|[^,])*?)` - // pattern := "\\s*((\\\"(.|[^\"])*\\\"|[^,])*" + - // "\\b\\w+([-+.]\\w+)*\\@\\w+[-\\.\\w]*\\.([-\\.\\w]+)*\\w\\b)>?)" - pattern = `.*` + strings.ToLower(name) + `.*` - var re *regexp.Regexp = nil - var err os.Error = nil - if re,err = regexp.Compile(pattern); err != nil { - log.Printf("error: %v\n", err) - return - } - - headers := []string{"from"} - if pass == 1 { - headers = append(headers, "to", "cc", "bcc") - } - - for ;msgs.Valid();msgs.MoveToNext() { - msg := msgs.Get() - //println("==> msg [", msg.GetMessageId(), "]") - for _,header := range headers { - froms := strings.ToLower(msg.GetHeader(header)) - //println(" froms: ["+froms+"]") - for _,from := range strings.Split(froms, ",", -1) { - from = strings.Trim(from, " ") - match := re.FindString(from) - //println(" -> match: ["+match+"]") - occ,ok := freqs[match] - if !ok { - freqs[match] = 0 - occ = 0 - } - freqs[match] = occ+1 - } - } - } - return -} - -func search_address_passes(queries [3]*notmuch.Query, name string) []string { - var val []string - addr_freq := make(map[string]*mail_addr_freq) - addr_to_realname := make(map[string]*frequencies) - - var pass uint = 0 // 0-based - for _,query := range queries { - if query == nil { - //println("**warning: idx [",idx,"] contains a nil query") - continue - } -