diff options
author | Camil Staps | 2020-02-05 12:11:21 +0100 |
---|---|---|
committer | Camil Staps | 2020-02-05 12:11:21 +0100 |
commit | ed07341890f277c4c526fa3fff8dc29df2258849 (patch) | |
tree | c98757cb42e756c5bc6a21fe4057210820aec8d9 /mail.php | |
parent | Add sequence,added_at, and updated_at to events table; implement SEQUENCE in ... (diff) |
Allow typos in mail headers (up to edit distance 1)
Diffstat (limited to 'mail.php')
-rw-r--r-- | mail.php | 43 |
1 files changed, 18 insertions, 25 deletions
@@ -156,31 +156,24 @@ function mail_parse_message ($body,$prefill_info=[]) $key=trim ($parts[0]); $val=trim ($parts[1]); - switch ($key){ - case 'Title': - $info['title']=$val; - break; - case 'Location': - $info['location']=$val; - break; - case 'Source': - $info['source']=$val; - break; - case 'Dates': - $parts=explode ('to',$val); - if (count ($parts)==2){ - $info['start_date']=trim ($parts[0]); - $info['end_date']=trim ($parts[1]); - } else { - $info['start_date']=$info['end_date']=$val; - } - break; - case 'Keywords': - $info['keywords']=array_map ('trim',explode (';',$val)); - break; - default: - $warnings[]='Unknown key '.$key; - } + if (levenshtein ($key,'Title') < 2) + $info['title']=$val; + else if (levenshtein ($key,'Location') < 2) + $info['location']=$val; + else if (levenshtein ($key,'Source') < 2) + $info['source']=$val; + else if (levenshtein ($key,'Dates') < 2){ + $parts=explode ('to',$val); + if (count ($parts)==2){ + $info['start_date']=trim ($parts[0]); + $info['end_date']=trim ($parts[1]); + } else { + $info['start_date']=$info['end_date']=$val; + } + } else if (levenshtein ($key,'Keywords') < 2) + $info['keywords']=array_map ('trim',explode (';',$val)); + else + $warnings[]='Unknown key '.$key; } $info['description']=trim (implode ("\n",array_slice ($lines,$i))); |