fix: phone leak, field-by-value detection, strict Flamingo email fallback
Three pilot-surfaced issues in one pass: 1. PhoneParser regex used '\s' in the candidate character class, so a digit on a following flattened line bled into the phone. '+7977 6277470\n1' (phone + trailing checkbox value) parsed as 12 digits, producing '+797762774701'. Replaced '\s' with a literal space so newlines/tabs stop the candidate. 2. Custom-themed forms don't use 'your-name' / 'your-email' keys (washanyanya.ru has text-211 / text-212 / name_user). Added FieldDetector::find_name + find_email as fallbacks. Classifier and MessageFormatter now call them if no standard key matches, so 'Александр' in text-211 is recognised as a cyrillic name and scored / displayed accordingly. 3. FlamingoHelper copied '_from_email' into 'your-email' without validating it. Flamingo derives that meta from whatever field it considers "first"; on phone-first forms it ends up holding the phone number. Now we only copy _from_email if it contains '@', and dropped the _from_name shortcut entirely — FieldDetector handles the name via the actual field values. Tests: +1 FieldDetectorTest (13 cases); +2 PhoneParserTest cases for newline/tab bleeds; +1 ClassifierTest case; +1 MessageFormatterTest case for custom field keys. Full suite 53/53 green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -63,7 +63,8 @@ cf7-spam-to-telegram/
|
||||
│ ├── class-classifier.php # Эвристика, score → label, reasons
|
||||
│ ├── class-phone-parser.php # Нормализация RU-телефонов
|
||||
│ ├── class-domain-formatter.php # Punycode → кириллица (idn_to_utf8)
|
||||
│ ├── class-message-formatter.php # Сборка HTML-сообщения, inline-клавиатура
|
||||
│ ├── class-field-detector.php # Fallback поиск имени/email когда ключи формы нестандартны
|
||||
│ ├── class-message-formatter.php # Сборка HTML-сообщения
|
||||
│ ├── class-retro-importer.php # Ретро-выгрузка из Flamingo
|
||||
│ ├── class-flamingo-helper.php # Извлечение полей и reason из Flamingo
|
||||
│ └── sources/
|
||||
@@ -221,6 +222,13 @@ apply_filters('cf7stg_classifier_keywords', $default_keywords);
|
||||
apply_filters('cf7stg_classifier_thresholds', ['client' => 3, 'spam' => -2]);
|
||||
```
|
||||
|
||||
**Поиск полей формы.** Сначала пробуются известные CF7-ключи — `your-name`, `name`, `имя`, `fio` для имени; `your-email`, `email`, `e-mail`, `mail` для e-mail; `your-message`, `message`, `comment`, `сообщение`, `вопрос` для текста. Если ничего не нашлось (например, на сайте форма с кастомными именами полей `text-211`, `name_user` и т.п.), подключается `FieldDetector`:
|
||||
|
||||
- `find_name(fields)` — первое значение без цифр/URL/@, длиной 2..80, состоящее только из letter-characters (любой скрипт), пробелов, дефисов и апострофов.
|
||||
- `find_email(fields)` — первое значение, матчащее `^\S+@\S+\.\S+$`.
|
||||
|
||||
Телефон всегда ищется `PhoneParser::parse()` по конкатенации всех полей — имена ключей не важны.
|
||||
|
||||
## 9. MessageFormatter — формат сообщения в Telegram
|
||||
|
||||
- **parse_mode:** `HTML` (строже и предсказуемее, чем MarkdownV2).
|
||||
|
||||
Reference in New Issue
Block a user