Coder Social home page Coder Social logo

go-proton-api's Introduction

Go Proton API

CI Status GoDoc Go Report Card License

This repository holds Go Proton API, a Go library implementing a client and development server for (a subset of) the Proton REST API.

The license can be found in the LICENSE file.

For the contribution policy, see CONTRIBUTING.

Environment variables

Most of the integration tests run locally. The ones that interact with Proton servers require the following environment variables set:

  • GO_PROTON_API_TEST_USERNAME
  • GO_PROTON_API_TEST_PASSWORD

Contribution

The library is maintained by Proton AG, and is not actively looking for contributors.

go-proton-api's People

Contributors

cuthix avatar electronafta avatar jameshoulahan avatar lbeernaertproton avatar rlejeune74 avatar xmichelo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-proton-api's Issues

utf-8" prefix on filenames when sending through smtp directly

When sending mail throught the smtp connection, the file attachments have the prefix utf8" on their filename.

2023-10-19_12-43

I send mails through this service:
https://github.com/ddvk/rmfakecloud

The corresponding line of code is found here:
https://github.com/ddvk/rmfakecloud/blob/master/internal/email/smtp.go#L84

The utf-8 prefix is based on RFC, a stackoverflow thread related to this: https://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http

Where are the docs on how to use this library?

I am trying to create a little command line client for getting my contact email addresses. Here is my code so far:

package main

import (
	"context"
	"fmt"
	"os"
	"os/signal"
	"syscall"

	"github.com/ProtonMail/go-proton-api"
	"golang.org/x/term"
)

func fatal(err error) {
	fmt.Fprintf(os.Stderr, "%v\n", err)
	os.Exit(1)
}

func main() {
	ctx := context.Background()

	// Create context that becomes done when various signals are received
	ctx, fn := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
	defer fn()

	// How da fuck do you get a valid app version...
	manager := proton.New(proton.WithAppVersion("[email protected]"), proton.WithDebug(true))
	defer manager.Close()

	client, auth, err := manager.NewClientWithLogin(ctx, "email", []byte("password"))
	if err != nil {
		fatal(err)
	}
	defer client.Close()

	if auth.TwoFA.Enabled&proton.HasTOTP != 0 {
		if term.IsTerminal(syscall.Stdin) {
			fmt.Print("TOTP: ")
		}

		code, err := term.ReadPassword(syscall.Stdin)
		if err != nil {
			fatal(err)
		}

		if err := client.Auth2FA(ctx, proton.Auth2FAReq{TwoFactorCode: string(code)}); err != nil {
			panic(err)
		}
	}

	contacts, err := client.GetAllContacts(ctx)
	if err != nil {
		fatal(err)
	}

	for _, contact := range contacts {
		fmt.Println(contact.Name)
	}
}

I have two questions:

  1. What should I put for the app version? Impersonating the web client seems stupid to me, but gets me past the first hurdle.
  2. This gets me to the CAPTCHA which I then need to complete. Is this avoidable? This program would be called tens of times a day. If I had to complete CAPTCHAs all day everyday, I would die. I am assuming I can complete it once, and get a token which I can then login with in subsequent program invocations. Is there an example of some go code which handles this flow?

The interface seems fairly easy to deal with except for the lacking documentation on completing the auth flow.

Sorting field in GetMessageMetadata

Hi,

In commit ca6c1de sorting order was added, but it is still impossible to sort by anything other than the ID.

Would it be acceptable to also add the Sort field ?

Quick proof of concept :

index 629bdbd..56c2a96 100644
--- a/message.go
+++ b/message.go
@@ -246,15 +246,16 @@ func (c *Client) GetMessageMetadataPage(ctx context.Context, page, pageSize int,
 
 		Page     int
 		PageSize int
-
-		Sort string
 	}{
 		MessageFilter: filter,
 
 		Page:     page,
 		PageSize: pageSize,
+	}
 
-		Sort: "ID",
+	/* keep default sort to maintain backward compatibility */
+	if req.Sort == "" {
+		req.Sort = "ID"
 	}
 
 	for {
diff --git a/message_types.go b/message_types.go
index 4d5fe95..a6ef6d9 100644
--- a/message_types.go
+++ b/message_types.go
@@ -55,6 +55,7 @@ type MessageFilter struct {
 	ExternalID string `json:",omitempty"`
 	LabelID    string `json:",omitempty"`
 	EndID      string `json:",omitempty"`
+	Sort       string `json:",omitempty"`
 	Desc       Bool
 }

Thanks !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.