Skip to content
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

Remove new gmail reply format #64

Open
wants to merge 4 commits into
base: master
from
Open

Remove new gmail reply format #64

wants to merge 4 commits into from

Conversation

@mfbmina
Copy link

mfbmina commented Dec 22, 2017

Gmail is using another format to replies: Eg. "DATETIME NAME :"

This PR removes it too.

@adamcrown
Copy link

adamcrown commented Mar 28, 2018

We had this exact problem and this fixed it for us. It would be great to have this merged and a new version released.

@mfbmina
Copy link
Author

mfbmina commented Apr 4, 2018

@tenderlove the last commit in this gem was yours, can you check this PR please?

@bcackerman
Copy link

bcackerman commented Aug 7, 2018

Can we get these merged in?

@cezartiv
Copy link

cezartiv commented Sep 17, 2018

We also have exactly this case patching now. Can anyone please merge this in?

@mattyoho
Copy link
Collaborator

mattyoho commented Jan 24, 2019

@mfbmina Sorry for lack of attention here, but thanks for opening this PR!

I noticed that the added test case seems to pass with or without the change, probably because the two calls share an implementation.

If you're still game for it, could you update the test case to be based on a string literal, similar to other nearby tests? I'll do what I can to facilitate incorporating the patch into a new release. 🙇

@MelizzaP
Copy link

MelizzaP commented Oct 22, 2019

@mattyoho is the only thing blocking this merge the test case? If I fixed it could this be merged?

@mfbmina mfbmina force-pushed the mfbmina:master branch from 02433d2 to 8d4ecb5 Oct 22, 2019
@mfbmina
Copy link
Author

mfbmina commented Oct 22, 2019

@mattyoho @MelizzaP tests are fixed now! Sorry for taking so long 😄

@mattyoho
Copy link
Collaborator

mattyoho commented Oct 22, 2019

@mfbmina @MelizzaP Thanks for taking a look at this PR again!

Appreciate the updated test, @mfbmina. 👍

Unfortunately, coming back to this pull request, I need to ask for some further changes to how the patch is structured before merging, because it works differently than the existing code for detecting a quote header does.

Here in this PR we're removing the Google Mail quote header from the incoming text on the "first pass" that performs some line normalization prior to the "second pass" of line-by-line scanning. (I use quotes here because the code isn't explicitly structured as a multi-pass implementation, though de facto it is.)

But the existing quote header detection leaves the header text in place so that it's subsequently included in a quote fragment on that second pass.

Adjacent to the addition here, the existing detection just normalizes the header text to remove any newlines that may have been introduced by the line-wrapping conventions for email messages:

if text =~ /^(?!On.*On\s.+?wrote:)(On\s(.+?)wrote:)$/m
# Remove all new lines from the reply header.
text.gsub! $1, $1.gsub("\n", " ")

It then later uses quote_header? to decided whether to also include a line not preceded by > with a quote fragment being built:

# If the line matches the current fragment, add it. Note that a common
# reply header also counts as part of the quoted Fragment, even though
# it doesn't start with `>`.
if @fragment &&
((@fragment.quoted? == is_quoted) ||
(@fragment.quoted? && (quote_header?(line) || line == EMPTY)))
@fragment.lines << line

Where the definition of quote_header? uses a simplified version of the regular expression used during the normalization pass to remove inserted newlines:

# Detects if a given line is a header above a quoted area. It is only
# checked for lines preceding quoted regions.
#
# line - A String line of text from the email.
#
# Returns true if the line is a valid header, or false.
def quote_header?(line)
line =~ /^:etorw.*nO$/
end

So what I would ask is for two changes:

  1. Rather than remove the Gmail quote header text, normalize it to remove inserted newlines, as is being done for the existing header detection.
  2. Update the quote_header? implementation to also detect the Gmail format.

This will have the benefits of not stripping the header text and also associating the newline that follows it with the quote block.

With those changes I think we can merge and then cut a pre-release version of the gem that includes the patch. Happy to discuss things further if needed.

Thank you for contributing!

@mfbmina
Copy link
Author

mfbmina commented Oct 23, 2019

@mattyoho I applied the changes that you required! Hope that solves all issues 👍

@MelizzaP
Copy link

MelizzaP commented Oct 29, 2019

thanks @mfbmina and @mattyoho 😄! This fixes an issue my team is having, any estimated timeline on a merge and new release?

@mfbmina
Copy link
Author

mfbmina commented Nov 8, 2019

@mattyoho do you had a chance to look?

@MelizzaP
Copy link

MelizzaP commented Dec 5, 2019

@mfbmina is this ok to merge?

@mfbmina
Copy link
Author

mfbmina commented Dec 5, 2019

@MelizzaP I think so... Tests are passing and I did the requested changes.

@MelizzaP
Copy link

MelizzaP commented Dec 6, 2019

whoops, sorry, I tagged the wrong person. @mattyoho is this ok to merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.