Repository navigation
A local reply leaves out the people the answered message blind copied #609
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package mail | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/basecamp/hey-sdk/go/pkg/generated" | ||
| ) | ||
|
|
||
| // ReplyRecipientsFor answers who a reply to this message goes to when HEY's own prefill | ||
| // is out of reach: the message's own recipients, with whoever sent it moved onto the To | ||
| // line. That is what HEY does in Entry::Addressed#participating_contacts_in_reply_by_kind, | ||
| // so a reply reaches the person who wrote the message as well as everyone they wrote to. | ||
| // The people it blind copied stay off the reply, as HEY leaves them off, unless they are | ||
| // all the audience there is: see keepsBlindCopied. | ||
| func ReplyRecipientsFor(message generated.Message) ReplyRecipients { | ||
| sender := message.Sender.EmailAddress | ||
| if sender == "" { | ||
| sender = message.Creator.EmailAddress | ||
| } | ||
| return replyRecipientsAddressed(message.Addressed, sender) | ||
| } | ||
|
|
||
| func replyRecipientsAddressed(addressed generated.Addressed, sender string) ReplyRecipients { | ||
| recipients := ReplyRecipients{ | ||
| To: addressesOf(addressed.Directly, sender), | ||
| CC: addressesOf(addressed.Copied, sender), | ||
| } | ||
| if keepsBlindCopied(addressed, sender) { | ||
| recipients.BCC = addressesOf(addressed.Blindcopied, sender) | ||
| } | ||
| if sender != "" { | ||
| recipients.To = append(recipients.To, sender) | ||
| } | ||
| return recipients | ||
| } | ||
|
|
||
| // keepsBlindCopied is HEY's rule (haystack#9169) for whether a reply keeps the people the | ||
| // answered message blind copied: only when they are the whole audience, because blind | ||
| // copying is often "this once" and a follow-up shouldn't reach them unseen. Nobody is left | ||
| // to address once the sender, who is the replier when they answer their own message | ||
| // (the fallback cannot tell otherwise), is set aside, as with "To: me, Bcc: the list" | ||
| // or a thread of only blind copied people. | ||
| func keepsBlindCopied(addressed generated.Addressed, sender string) bool { | ||
| visible := append(append([]generated.Contact{}, addressed.Directly...), addressed.Copied...) | ||
| return len(addressesOf(visible, sender)) == 0 | ||
| } | ||
|
|
||
| // addressesOf answers the contacts' email addresses, dropping blanks, repeats, and the | ||
| // one address HEY addresses directly instead. | ||
| func addressesOf(contacts []generated.Contact, excluding string) []string { | ||
| seen := map[string]bool{strings.ToLower(excluding): true} | ||
| var addresses []string | ||
| for _, contact := range contacts { | ||
| address := strings.TrimSpace(contact.EmailAddress) | ||
| key := strings.ToLower(address) | ||
| if address != "" && !seen[key] { | ||
| seen[key] = true | ||
| addresses = append(addresses, address) | ||
| } | ||
| } | ||
| return addresses | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package mail | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "testing" | ||
|
|
||
| "github.com/basecamp/hey-sdk/go/pkg/generated" | ||
| ) | ||
|
|
||
| func contacts(addresses ...string) []generated.Contact { | ||
| list := make([]generated.Contact, 0, len(addresses)) | ||
| for _, address := range addresses { | ||
| list = append(list, generated.Contact{EmailAddress: address}) | ||
| } | ||
| return list | ||
| } | ||
|
|
||
| func TestReplyRecipientsForBlindCopies(t *testing.T) { | ||
| sender := generated.Contact{EmailAddress: "jane@example.com"} | ||
| tests := []struct { | ||
| name string | ||
| addressed generated.Addressed | ||
| want ReplyRecipients | ||
| }{ | ||
| { | ||
| name: "blind copies stay off a reply with a visible audience", | ||
| addressed: generated.Addressed{Directly: contacts("rick@example.com"), Blindcopied: contacts("secret@example.com")}, | ||
| want: ReplyRecipients{To: []string{"rick@example.com", "jane@example.com"}}, | ||
| }, | ||
| { | ||
| name: "blind copies are kept when they are the whole audience", | ||
| addressed: generated.Addressed{Directly: contacts("jane@example.com"), Blindcopied: contacts("list@example.com")}, | ||
| want: ReplyRecipients{To: []string{"jane@example.com"}, BCC: []string{"list@example.com"}}, | ||
| }, | ||
| } | ||
| for _, testCase := range tests { | ||
| t.Run(testCase.name, func(t *testing.T) { | ||
| got := ReplyRecipientsFor(generated.Message{Sender: sender, Addressed: testCase.addressed}) | ||
| if !reflect.DeepEqual(got, testCase.want) { | ||
| t.Fatalf("got %+v, want %+v", got, testCase.want) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.