-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Outlook Mail: map Outlook IDs to auto-incrementing numerical IDs #46
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module github.com/gptscript-ai/tools/apis/outlook/common | ||
|
||
go 1.23.0 | ||
|
||
require ( | ||
github.com/glebarez/sqlite v1.11.0 | ||
gorm.io/gorm v1.25.7 | ||
) | ||
|
||
require ( | ||
github.com/dustin/go-humanize v1.0.1 // indirect | ||
github.com/glebarez/go-sqlite v1.21.2 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/jinzhu/inflection v1.0.0 // indirect | ||
github.com/jinzhu/now v1.1.5 // indirect | ||
github.com/mattn/go-isatty v0.0.17 // indirect | ||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect | ||
golang.org/x/sys v0.7.0 // indirect | ||
modernc.org/libc v1.22.5 // indirect | ||
modernc.org/mathutil v1.5.0 // indirect | ||
modernc.org/memory v1.5.0 // indirect | ||
modernc.org/sqlite v1.23.1 // indirect | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= | ||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= | ||
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo= | ||
github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k= | ||
github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw= | ||
github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ= | ||
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ= | ||
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo= | ||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= | ||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= | ||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= | ||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= | ||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= | ||
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= | ||
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= | ||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= | ||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= | ||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= | ||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= | ||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A= | ||
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= | ||
modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE= | ||
modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY= | ||
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ= | ||
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E= | ||
modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds= | ||
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU= | ||
modernc.org/sqlite v1.23.1 h1:nrSBg4aRQQwq59JpvGEQ15tNxoO5pX/kUjcRNwSAGQM= | ||
modernc.org/sqlite v1.23.1/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk= |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package id | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"path" | ||
"strconv" | ||
|
||
"github.com/glebarez/sqlite" | ||
"gorm.io/gorm" | ||
"gorm.io/gorm/logger" | ||
) | ||
|
||
type CacheObject struct { | ||
ID uint `gorm:"primaryKey;autoIncrement"` | ||
OutlookID string `gorm:"index"` | ||
} | ||
|
||
var dbPath = path.Join(os.Getenv("GPTSCRIPT_WORKSPACE_DIR"), "outlookcache.db") | ||
|
||
func loadDB() (*gorm.DB, error) { | ||
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{ | ||
Logger: logger.New(log.New(os.Stdout, "\r\n", log.LstdFlags), logger.Config{LogLevel: logger.Error, IgnoreRecordNotFoundError: true}), | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to load the Outlook cache database: %w", err) | ||
} | ||
|
||
if err = db.AutoMigrate(&CacheObject{}); err != nil { | ||
return nil, fmt.Errorf("failed to migrate the Outlook cache database: %w", err) | ||
} | ||
|
||
return db, nil | ||
} | ||
|
||
func GetOutlookID(id string) (string, error) { | ||
if id == "" { | ||
return "", fmt.Errorf("ID is required") | ||
} | ||
|
||
idNum, err := strconv.Atoi(id) | ||
if err != nil { | ||
// If the ID does not convert to a number, it's most likely already an Outlook ID, so we just return it back. | ||
return id, nil | ||
} | ||
|
||
db, err := loadDB() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
var cache CacheObject | ||
if err = db.First(&cache, idNum).Error; err != nil { | ||
return "", fmt.Errorf("failed to get the Outlook ID: %w", err) | ||
} | ||
|
||
return cache.OutlookID, nil | ||
} | ||
|
||
func SetOutlookID(outlookID string) (string, error) { | ||
if outlookID == "" { | ||
return "", fmt.Errorf("Outlook ID is required") | ||
} | ||
|
||
db, err := loadDB() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// First we try looking for an existing one. | ||
var existing CacheObject | ||
if err = db.Where("outlook_id = ?", outlookID).First(&existing).Error; err == nil { | ||
return strconv.Itoa(int(existing.ID)), nil | ||
} | ||
|
||
// If it doesn't exist, we create a new one. | ||
cache := CacheObject{OutlookID: outlookID} | ||
if err = db.Create(&cache).Error; err != nil { | ||
return "", fmt.Errorf("failed to set the Outlook ID: %w", err) | ||
} | ||
|
||
return strconv.Itoa(int(cache.ID)), nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,11 @@ module github.com/gptscript-ai/tools/apis/outlook/mail/code | |
|
||
go 1.23.0 | ||
|
||
replace github.com/gptscript-ai/tools/apis/outlook/common => github.com/g-linville/tools/apis/outlook/common v0.0.0-20240903203431-d7bfd26dc70d | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is pointing at my fork for now. Unfortunately I can't really change this until after I merge this PR. Should I open up a second PR to introduce the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's fine to merge and immediately create another PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason this common package has to be separate go module? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had separate Go modules for the manage and read tools, and want this code to be usable by both of them without one of them being the distinct "owner" of it |
||
|
||
require ( | ||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0 | ||
github.com/gptscript-ai/tools/apis/outlook/common v0.0.0 | ||
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056 | ||
github.com/microsoftgraph/msgraph-sdk-go v1.47.0 | ||
) | ||
|
@@ -12,9 +15,15 @@ require ( | |
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect | ||
github.com/cjlapao/common-go v0.0.39 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/dustin/go-humanize v1.0.1 // indirect | ||
github.com/glebarez/go-sqlite v1.21.2 // indirect | ||
github.com/glebarez/sqlite v1.11.0 // indirect | ||
github.com/go-logr/logr v1.4.1 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/jinzhu/inflection v1.0.0 // indirect | ||
github.com/jinzhu/now v1.1.5 // indirect | ||
github.com/mattn/go-isatty v0.0.17 // indirect | ||
github.com/mattn/go-runewidth v0.0.9 // indirect | ||
github.com/microsoft/kiota-abstractions-go v1.6.1 // indirect | ||
github.com/microsoft/kiota-authentication-azure-go v1.0.2 // indirect | ||
|
@@ -26,13 +35,20 @@ require ( | |
github.com/microsoftgraph/msgraph-sdk-go-core v1.2.0 // indirect | ||
github.com/olekukonko/tablewriter v0.0.5 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect | ||
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect | ||
github.com/std-uritemplate/std-uritemplate/go v0.0.57 // indirect | ||
github.com/stretchr/testify v1.9.0 // indirect | ||
go.opentelemetry.io/otel v1.24.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.24.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.24.0 // indirect | ||
golang.org/x/net v0.28.0 // indirect | ||
golang.org/x/sys v0.23.0 // indirect | ||
golang.org/x/text v0.17.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
gorm.io/gorm v1.25.7 // indirect | ||
modernc.org/libc v1.22.5 // indirect | ||
modernc.org/mathutil v1.5.0 // indirect | ||
modernc.org/memory v1.5.0 // indirect | ||
modernc.org/sqlite v1.23.1 // indirect | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the pure Go (no CGo) implementation of the SQLite driver for GORM.