~psic4t/qcard

0fa8bcd092e601f2aafff613778a83881376e87a — psic4t a month ago 9b83b0f master
remove binary
5 files changed, 55 insertions(+), 8 deletions(-)

M defines.go
M helpers.go
M main.go
M parse.go
D qcard
M defines.go => defines.go +1 -0
@@ 20,6 20,7 @@ var showEmailOnly *bool
var displayFlag bool
var toFile bool
var filter string
var orgFilter string
var searchterm string

//var colorBlock string = "█"

M helpers.go => helpers.go +5 -0
@@ 230,6 230,11 @@ func filterMatch(fullName string) bool {
	return re.FindString(fullName) != ""
}

func filterOrgMatch(org string) bool {
	re, _ := regexp.Compile(`(?i)` + orgFilter)
	return re.FindString(org) != ""
}

func deleteContact(abNo int, contactFilename string) (status string) {
	if contactFilename == "" {
		log.Fatal("No contact filename given")

M main.go => main.go +5 -3
@@ 216,7 216,8 @@ func main() {
	if len(os.Args[1:]) > 0 {
		searchterm = os.Args[1]
	}
	flag.StringVar(&filter, "s", "", "Search term")
	flag.StringVar(&filter, "s", "", "Search (part of) name")
	flag.StringVar(&orgFilter, "so", "", "Search (part of) organisation")
	//flag.BoolVar(&showInfo, "i", false, "Show additional info like description and location for contacts")
	flag.BoolVar(&showFilename, "f", false, "Show contact filename for editing or deletion")
	flag.BoolVar(&displayFlag, "p", false, "Print VCF file piped to qcard (for CLI mail tools like mutt)")


@@ 233,9 234,10 @@ func main() {
	flagset := make(map[string]bool) // map for flag.Visit. get bools to determine set flags
	flag.Visit(func(f *flag.Flag) { flagset[f.Name] = true })

	//if *showAddressbooks {
	//}
	//if flagset["l"] {
	if *showAddressbooks {
	}
	if flagset["l"] {
		getAbList()
	} else if flagset["delete"] {
		deleteContact(*abNo, *contactDelete)

M parse.go => parse.go +44 -5
@@ 1,6 1,7 @@
package main

import (
	"fmt"
	"regexp"
	"strings"
)


@@ 42,14 43,49 @@ func parseContactPhoneWork(contactData *string) string {
	return trimField(result, "(?i)TEL;TYPE=WORK:")
}

func parseContactEmail(contactData *string) string {
	var emailType string
	re, _ := regexp.Compile(`(?i)EMAIL(;TYPE=(.*))?:.*?\n`)
	parts := re.FindStringSubmatch(*contactData)

	if len(parts) > 1 {
		types := strings.Split(parts[2], ",")
		for _, i := range types {
			//fmt.Println(i)
			switch strings.ToLower(i) {
			case "internet":
				emailType = "home"
			case "home":
				emailType = "home"
			case "pref":
				emailType = "home"
			case "work":
				emailType = "work"
			}
		}
	}

	fmt.Println(emailType)
	result := re.FindString(*contactData)
	return trimField(result, "(?i)EMAIL(;TYPE=(.*))?:")
}

func parseContactEmailHome(contactData *string) string {
	re, _ := regexp.Compile(`(?i)EMAIL(;TYPE=(HOME|INTERNET|PREF|INTERNET,HOME))?:.*?\n`)
	/*workre, _ := regexp.Compile(`(?i)EMAIL;TYPE=(.*WORK.*):.*?\n`) // check, if work email
	if workre.FindString(*contactData) != "" {
		fmt.Println("yes")
		return "" // if work email, get out
	}*/
	re, _ := regexp.Compile(`(?i)EMAIL(;TYPE=(HOME|INTERNET|PREF|INTERNET,HOME|HOME,INTERNET))?:.*?\n`)
	//re, _ := regexp.Compile(`(?i)EMAIL(;TYPE=(.*))?:.*?\n`)
	result := re.FindString(*contactData)
	return trimField(result, "(?i)EMAIL(;TYPE=(HOME|INTERNET|PREF|INTERNET,HOME))?:")
	return trimField(result, "(?i)EMAIL(;TYPE=(.*))?:")

}

func parseContactEmailWork(contactData *string) string {
	re, _ := regexp.Compile(`(?i)EMAIL;TYPE=(WORK|INTERNET,WORK):.*?\n`)
	//re, _ := regexp.Compile(`(?i)EMAIL;TYPE=(WORK|INTERNET,WORK):.*?\n`)
	re, _ := regexp.Compile(`(?i)EMAIL;TYPE=(.*WORK.*):.*?\n`)
	result := re.FindString(*contactData)
	return trimField(result, "(?i)EMAIL;TYPE=(WORK|INTERNET,WORK):")
}


@@ 107,8 143,11 @@ func parseContactNickname(contactData *string) string {
func parseMain(contactData *string, contactsSlice *[]contactStruct, href, color string) {
	//fmt.Println(parseContactName(contactData))
	fullName := parseContactFullName(contactData)
	organisation := parseContactOrg(contactData)

	if (filter == "") || (filterMatch(fullName) == true) {
	//if flagset["so"] {
	// TODO: How to filter with name and org?
	if (filter == "") || ((filterMatch(fullName) == true) || (filterOrgMatch(organisation) == true)) {
		data := contactStruct{
			Href:         href,
			Color:        color,


@@ 116,7 155,7 @@ func parseMain(contactData *string, contactsSlice *[]contactStruct, href, color 
			name:         parseContactName(contactData),
			title:        parseContactTitle(contactData),
			role:         parseContactRole(contactData),
			organisation: parseContactOrg(contactData),
			organisation: organisation,
			phoneCell:    parseContactPhoneCell(contactData),
			phoneHome:    parseContactPhoneHome(contactData),
			phoneWork:    parseContactPhoneWork(contactData),

D qcard => qcard +0 -0