nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: mailgun/mailgun-go
Pull request #242 (2021-01-19 09:21:44)

Add UpdateDomainDkimSelector
Mailgun API supports update dkim selector for a domain as documented here https://documentation.mailgun.com/en/latest/api-domains.html#domains
I don't see any like that in this library, so I added one, please check. Thank you


Patch:
diff --git a/domains.go b/domains.go
index 221c6ee..afcf9f2 100644
--- a/domains.go
+++ b/domains.go
@@ -378,6 +378,18 @@ func (mg *MailgunImpl) UpdateOpenTracking(ctx context.Context, domain, active st
 	return err
 }
 
+// Update the DKIM selector for a domain
+func (mg *MailgunImpl) UpdateDomainDkimSelector(ctx context.Context, domain string, dkim_selector string) error {
+	r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + domain + "/dkim_selector")
+	r.setClient(mg.Client())
+	r.setBasicAuth(basicAuthUser, mg.APIKey())
+
+	payload := newUrlEncodedPayload()
+	payload.addValue("dkim_selector", dkim_selector)
+	_, err := makePutRequest(ctx, r, payload)
+	return err
+}
+
 func boolToString(b bool) string {
 	if b {
 		return "true"


Test patch:
diff --git a/domains_test.go b/domains_test.go
index 85d4174..0c5dce4 100644
--- a/domains_test.go
+++ b/domains_test.go
@@ -153,3 +153,13 @@ func TestDomainVerify(t *testing.T) {
 	_, err := mg.VerifyDomain(ctx, testDomain)
 	ensure.Nil(t, err)
 }
+
+func TestDomainDkimSelector(t *testing.T) {
+	mg := mailgun.NewMailgun(testDomain, testKey)
+	mg.SetAPIBase(server.URL())
+	ctx := context.Background()
+
+	// Update Domain DKIM selector
+	err := mg.UpdateDomainDkimSelector(ctx, testDomain, "gotest")
+	ensure.Nil(t, err)
+}
Repository: mailgun/mailgun-go
Pull request #259 (2021-06-25 19:06:19)

add new VerifyAndReturnDomain that returns DomainResponse to comply with mailgun api docs
More about the issue here: https://github.com/mailgun/mailgun-go/issues/257

To avoid changing major version, as @thrawn01 proposed, I've introduced the new method, instead of changing the response of `VerifyDomain` method.  


Patch:
diff --git a/domains.go b/domains.go
index a1b3b71..99c428b 100644
--- a/domains.go
+++ b/domains.go
@@ -253,6 +253,18 @@ func (mg *MailgunImpl) VerifyDomain(ctx context.Context, domain string) (string,
 	return resp.Domain.State, err
 }
 
+// VerifyAndReturnDomain verifies & retrieves detailed information about the named domain.
+func (mg *MailgunImpl) VerifyAndReturnDomain(ctx context.Context, domain string) (DomainResponse, error) {
+	r := newHTTPRequest(generatePublicApiUrl(mg, domainsEndpoint) + "/" + domain + "/verify")
+	r.setClient(mg.Client())
+	r.setBasicAuth(basicAuthUser, mg.APIKey())
+
+	payload := newUrlEncodedPayload()
+	var resp DomainResponse
+	err := putResponseFromJSON(ctx, r, payload, &resp)
+	return resp, err
+}
+
 // Optional parameters when creating a domain
 type CreateDomainOptions struct {
 	Password           string


Test patch:
diff --git a/domains_test.go b/domains_test.go
index cd02815..38e0a7d 100644
--- a/domains_test.go
+++ b/domains_test.go
@@ -154,6 +154,15 @@ func TestDomainVerify(t *testing.T) {
 	ensure.Nil(t, err)
 }
 
+func TestDomainVerifyAndReturn(t *testing.T) {
+	mg := mailgun.NewMailgun(testDomain, testKey)
+	mg.SetAPIBase(server.URL())
+	ctx := context.Background()
+
+	_, err := mg.VerifyAndReturnDomain(ctx, testDomain)
+	ensure.Nil(t, err)
+}
+
 func TestDomainDkimSelector(t *testing.T) {
 	mg := mailgun.NewMailgun(testDomain, testKey)
 	mg.SetAPIBase(server.URL())
Repository: mailgun/mailgun-go
Pull request #286 (2022-05-20 14:01:09)

Changed url validation
Because of the base API url validation, it is currently not possible to use a url like `http://localhost/my-proxy/v3`.

My specific use case is to proxy the requests to the Mailgun api via a `https://my-internal-server/mailgun/v3` base. I cannot access the Mailgun API directly in the network but I have access to `my-internal-server`.

Using `https://my-internal-server/mailgun/v3`, I get an error that reads `BaseAPI must end with a /v2, /v3 or /v4`, which it does in my example, but the regex to validate the url is `^/v[2-4].*`, which checks if it _starts_ with the version segment.

Alltough I think this check could be removed completely (a user will notice the wrong URL when the request is sent, like they would notice a wrong username/password) this PR proposes to change the regex to just `/v[2-4].*` so only the presence of a `/v3` segment is validated, no matter where in the URL.

I guess it would be better to validate the URL somewhere where the actual `apiBase` field is available so we could actually validate if it ends in `/v3` but I did not find a way to implement it without breaking the api. The `httpRequest` struct does not know about the `apiBase` but only sees the fully constructed url which makes the validation for a specific format harder.


Patch:
diff --git a/httphelpers.go b/httphelpers.go
index 382659b..5156b6e 100644
--- a/httphelpers.go
+++ b/httphelpers.go
@@ -17,7 +17,7 @@ import (
 	"strings"
 )
 
-var validURL = regexp.MustCompile(`^/v[2-4].*`)
+var validURL = regexp.MustCompile(`/v[2-4].*`)
 
 type httpRequest struct {
 	URL               string


Test patch:
diff --git a/mailgun_test.go b/mailgun_test.go
index f091e34..8ac3f70 100644
--- a/mailgun_test.go
+++ b/mailgun_test.go
@@ -2,7 +2,10 @@ package mailgun_test
 
 import (
 	"context"
+	"encoding/json"
+	"fmt"
 	"net/http"
+	"net/http/httptest"
 	"testing"
 
 	"github.com/facebookgo/ensure"
@@ -33,3 +36,27 @@ func TestInvalidBaseAPI(t *testing.T) {
 	ensure.NotNil(t, err)
 	ensure.DeepEqual(t, err.Error(), `BaseAPI must end with a /v2, /v3 or /v4; setBaseAPI("https://host/v3")`)
 }
+
+func TestValidBaseAPI(t *testing.T) {
+	testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		var resp mailgun.DomainResponse
+		b, err := json.Marshal(resp)
+		ensure.Nil(t, err)
+
+		w.Write(b)
+	}))
+
+	apiBases := []string{
+		fmt.Sprintf("%s/v3", testServer.URL),
+		fmt.Sprintf("%s/proxy/v3", testServer.URL),
+	}
+
+	for _, apiBase := range apiBases {
+		mg := mailgun.NewMailgun(testDomain, testKey)
+		mg.SetAPIBase(apiBase)
+
+		ctx := context.Background()
+		_, err := mg.GetDomain(ctx, "unknown.domain")
+		ensure.Nil(t, err)
+	}
+}
Repository: mailgun/mailgun-go
Pull request #289 (2022-05-27 18:35:29)

Added special case for Host headers


Patch:
diff --git a/httphelpers.go b/httphelpers.go
index 3ff0d11..88121a5 100644
--- a/httphelpers.go
+++ b/httphelpers.go
@@ -359,6 +359,11 @@ func (r *httpRequest) curlString(req *http.Request, p payload) string {
 		}
 	}
 
+	// Special case for Host
+	if req.Host != "" {
+		parts = append(parts, fmt.Sprintf("-H \"Host: %s\"", req.Host))
+	}
+
 	//parts = append(parts, fmt.Sprintf(" --user '%s:%s'", r.BasicAuthUser, r.BasicAuthPassword))
 
 	if p != nil {


Test patch:
diff --git a/messages_test.go b/messages_test.go
index 112f62f..131686a 100644
--- a/messages_test.go
+++ b/messages_test.go
@@ -582,6 +582,8 @@ func TestAddOverrideHeader(t *testing.T) {
 	ensure.Nil(t, err)
 	ensure.DeepEqual(t, msg, exampleMessage)
 	ensure.DeepEqual(t, id, exampleID)
+
+	ensure.StringContains(t, mg.GetCurlOutput(), "Host:")
 }
 
 func TestCaptureCurlOutput(t *testing.T) {
Repository: mailgun/mailgun-go
Pull request #291 (2022-09-29 11:56:13)

CreateDomain: add support of `web_scheme`


Patch:
diff --git a/domains.go b/domains.go
index 99c428b..6642fb5 100644
--- a/domains.go
+++ b/domains.go
@@ -273,6 +273,7 @@ type CreateDomainOptions struct {
 	ForceDKIMAuthority bool
 	DKIMKeySize        int
 	IPS                []string
+	WebScheme          string
 }
 
 // CreateDomain instructs Mailgun to create a new domain for your account.
@@ -308,6 +309,9 @@ func (mg *MailgunImpl) CreateDomain(ctx context.Context, name string, opts *Crea
 		if len(opts.Password) != 0 {
 			payload.addValue("smtp_password", opts.Password)
 		}
+		if opts.WebScheme != "" {
+			payload.addValue("web_scheme", string(opts.WebScheme))
+		}
 	}
 	var resp DomainResponse
 	err := postResponseFromJSON(ctx, r, payload, &resp)


Test patch:
diff --git a/domains_test.go b/domains_test.go
index 38e0a7d..481e418 100644
--- a/domains_test.go
+++ b/domains_test.go
@@ -76,7 +76,7 @@ func TestAddDeleteDomain(t *testing.T) {
 
 	// First, we need to add the domain.
 	_, err := mg.CreateDomain(ctx, "mx.mailgun.test",
-		&mailgun.CreateDomainOptions{SpamAction: mailgun.SpamActionTag, Password: "supersecret"})
+		&mailgun.CreateDomainOptions{SpamAction: mailgun.SpamActionTag, Password: "supersecret", WebScheme: "https"})
 	ensure.Nil(t, err)
 
 	// Next, we delete it.
Repository: mailgun/mailgun-go
Pull request #325 (2024-08-09 10:00:58)

DE-1307 Add validate’s engagement results


Patch:
diff --git a/email_validation.go b/email_validation.go
index b4964ec..c7b50e5 100644
--- a/email_validation.go
+++ b/email_validation.go
@@ -22,7 +22,6 @@ type EmailVerificationParts struct {
 
 // EmailVerification records basic facts about a validated e-mail address.
 // See the ValidateEmail method and example for more details.
-//
 type EmailVerification struct {
 	// Indicates whether an email address conforms to IETF RFC standards.
 	IsValid bool `json:"is_valid"`
@@ -49,6 +48,18 @@ type EmailVerification struct {
 	Risk string `json:"risk"`
 	// Result
 	Result string `json:"result"`
+	// Engagement results are a macro-level view that explain an email recipient’s propensity to engage.
+	// https://documentation.mailgun.com/docs/inboxready/mailgun-validate/validate_engagement/
+	//
+	// Only for v4. To use the /v4 version of validations define MG_URL in the environment variable
+	// as `https://api.mailgun.net/v4` or set `v.SetAPIBase("https://api.mailgun.net/v4")`
+	Engagement *EngagementData `json:"engagement,omitempty"`
+}
+
+type EngagementData struct {
+	Engaging bool   `json:"engaging"`
+	Behavior string `json:"behavior,omitempty"`
+	IsBot    bool   `json:"is_bot"`
 }
 
 type v4EmailValidationResp struct {
@@ -62,6 +73,7 @@ type v4EmailValidationResp struct {
 	Reason              []string               `json:"reason"`
 	Risk                string                 `json:"risk"`
 	Result              string                 `json:"result"`
+	Engagement          *EngagementData        `json:"engagement,omitempty"`
 }
 
 type addressParseResult struct {
@@ -202,7 +214,9 @@ func (m *EmailValidatorImpl) validateV4(ctx context.Context, email string, mailB
 		IsRoleAddress:       res.IsRoleAddress,
 		Reasons:             res.Reason,
 		Result:              res.Result,
-		Risk:                res.Risk}, nil
+		Risk:                res.Risk,
+		Engagement:          res.Engagement,
+	}, nil
 }
 
 // ParseAddresses takes a list of addresses and sorts them into valid and invalid address categories.
diff --git a/mock_validation.go b/mock_validation.go
index 83ce278..c42fce3 100644
--- a/mock_validation.go
+++ b/mock_validation.go
@@ -34,6 +34,11 @@ func (ms *mockServer) validateEmailV4(w http.ResponseWriter, r *http.Request) {
 	results.Reason = []string{"no-reason"}
 	results.Risk = "unknown"
 	results.Result = "deliverable"
+	results.Engagement = &EngagementData{
+		Engaging: false,
+		Behavior: "disengaged",
+		IsBot:    false,
+	}
 	toJSON(w, results)
 }
 


Test patch:
diff --git a/email_validation_test.go b/email_validation_test.go
index 30af83f..7a3e0d2 100644
--- a/email_validation_test.go
+++ b/email_validation_test.go
@@ -51,6 +51,9 @@ func TestEmailValidationV4(t *testing.T) {
 	ensure.DeepEqual(t, ev.Reasons[0], "no-reason")
 	ensure.DeepEqual(t, ev.Risk, "unknown")
 	ensure.DeepEqual(t, ev.Result, "deliverable")
+	ensure.DeepEqual(t, ev.Engagement.Behavior, "disengaged")
+	ensure.DeepEqual(t, ev.Engagement.Engaging, false)
+	ensure.False(t, ev.Engagement.IsBot)
 }
 
 func TestParseAddresses(t *testing.T) {
Repository: mailgun/mailgun-go
Pull request #409 (2025-03-24 16:21:53)

EASY-597: Increase max tag limit to 10 per message
[EASY-597](https://mailgun.atlassian.net/browse/EASY-597):

As part of the broader tags project we are increasing the maximum number of tags per message to 10

[EASY-597]: https://mailgun.atlassian.net/browse/EASY-597?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ


Patch:
diff --git a/messages.go b/messages.go
index 657fb1e..2c4473f 100644
--- a/messages.go
+++ b/messages.go
@@ -19,7 +19,7 @@ import (
 const MaxNumberOfRecipients = 1000
 
 // MaxNumberOfTags represents the maximum number of tags that can be added for a message
-const MaxNumberOfTags = 3
+const MaxNumberOfTags = 10
 
 // CommonMessage structures contain both the message text and the envelope for an e-mail message.
 type CommonMessage struct {


Test patch:
diff --git a/tags_test.go b/tags_test.go
index 8be996e..425d111 100644
--- a/tags_test.go
+++ b/tags_test.go
@@ -27,6 +27,13 @@ func TestTags(t *testing.T) {
 	require.NoError(t, msg.AddTag("newsletter"))
 	require.NoError(t, msg.AddTag("homer"))
 	require.NoError(t, msg.AddTag("bart"))
+	require.NoError(t, msg.AddTag("marge"))
+	require.NoError(t, msg.AddTag("lisa"))
+	require.NoError(t, msg.AddTag("maggie"))
+	require.NoError(t, msg.AddTag("burns"))
+	require.NoError(t, msg.AddTag("milhouse"))
+	require.NoError(t, msg.AddTag("moe"))
+	require.NoError(t, msg.AddTag("selma"))
 	require.NotNil(t, msg.AddTag("disco-steve"))
 	require.NotNil(t, msg.AddTag("newsletter"))