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

Parse this: Tue Feb 16 2016 17:23:34 GMT+0800 #225

Closed
wants to merge 2 commits into from

Conversation

zhangao0086
Copy link

This PR contains parsing the broken format Tue Feb 16 2016 17:23:34 GMT+0800.

@dinhvh
Copy link
Owner

dinhvh commented Feb 28, 2016

Could you create a new function instead?
mailimf_hack_date_time_parse()

Then in MailCore, MessageHeader::importIMAPEnvelope(), use:

void MessageHeader::importIMAPEnvelope(struct mailimap_envelope * env)
{
    if (env->env_date != NULL) {
        size_t cur_token;
        struct mailimf_date_time * date_time;
        int r;

        cur_token = 0;
        r = mailimf_date_time_parse(env->env_date, strlen(env->env_date),
            &cur_token, &date_time);
        if (r == MAILIMF_NO_ERROR) {
            time_t timestamp;

            // date
            timestamp = timestampFromDate(date_time);
            setDate(timestamp);
            setReceivedDate(timestamp);
            mailimf_date_time_free(date_time);
        }

        if (r != MAILIMF_NO_ERROR) {
            r = mailimf_hack_date_time_parse(env->env_date, strlen(env->env_date),
            &cur_token, &date_time);
            if (r == MAILIMAP_NO_ERROR) {
                time_t timestamp;

                timestamp = timestampFromDate(imap_date);
                setDate(timestamp);
                setReceivedDate(timestamp);
                mailimf_date_time_free(date_time);
            }
        }

        if (r != MAILIMF_NO_ERROR) {
            struct mailimap_date_time * imap_date;

            r = mailimap_hack_date_time_parse(env->env_date, &imap_date, 0, NULL);
            if (r == MAILIMAP_NO_ERROR) {
                time_t timestamp;

                timestamp = timestampFromIMAPDate(imap_date);
                setDate(timestamp);
                setReceivedDate(timestamp);
                mailimap_date_time_free(imap_date);
            }
        }
    }

    ...

@zhangao0086
Copy link
Author

In my case, the MessageHeader::importIMAPEnvelope function is never getting called...

@dinhvh
Copy link
Owner

dinhvh commented Feb 29, 2016

ah ok, you're fetching the full header.
Could you still have a separate mailimf_hack_date_time_parse() and call it in mailimf_date_time_parse() if it fails to parse the date (on MAILIMF_ERROR_PARSE)?

Basically, you would replace calls to return r to res = r; goto err; and in the label 'err:`, you would call the workaround mailimf_hack_date_time_parse() if there's a parse error.

@zhangao0086
Copy link
Author

Updated. Please review again.

@zhangao0086
Copy link
Author

Any problems?

@dinhvh
Copy link
Owner

dinhvh commented Mar 5, 2016

I'm taking a closer look at the code to see the best way to do it.

@zhangao0086
Copy link
Author

I believe you have a better way :)

@dinhvh
Copy link
Owner

dinhvh commented Mar 7, 2016

I'm not sure. Anyway, the code you provided here is very useful.

@dinhvh
Copy link
Owner

dinhvh commented Mar 27, 2016

I eventually used something similar to the first commit. Thanks!

@dinhvh dinhvh closed this Mar 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants