public Classification ClassifyMail(Message mail) { NumMessages++; return null; }
public Classification ClassifyMail(Message mail) { if (mail.TextBody == null || mail.TextBody.Body == null) return null; var content = System.Text.Encoding.UTF8.GetString(mail.TextBody.Body); var title = GetSingleMatch(TitleStarter, TitleRegex, content, false); if (string.IsNullOrEmpty(title)) return null; var details = GetSingleMatch(DetailsStarter, DetailsRegex, content, false); if (string.IsNullOrEmpty(details)) { Show(content); return null; } var name = GetSingleMatch(NameStarter, NameRegEx, content, true); if (string.IsNullOrEmpty(name)) { Show(content); return null; } var elstr = new ElStr(); name = elstr.ToLatin(name); var phone = GetSingleMatch(TelephoneStarter, TelephoneRegex, content, false); var email = GetSingleMatch(EmailStarter, EmailRegex, content, true); if (string.IsNullOrEmpty(email)) { Show(content); return null; } var cover = GetSingleMatch(string.Empty, CoverLetter, content, false, RegexOptions.Singleline); if (string.IsNullOrEmpty(cover) || cover.Contains(NoCoverLetter)) { cover = string.Empty; } else { cover = cover.Replace("Συνοδευτική Επιστολή", string.Empty) .Replace("Βιογραφικό", string.Empty) .Replace("------------", string.Empty); } var classification = new Classification { AdUrl = details, CoverLetter = cover, Job = title, Name = name, Phone = phone, Submitted = mail.Headers.DateSent, Mail = email }; if (mail.Attachments != null && mail.Attachments.Count > 0) { classification.AttachmentName = mail.Attachments[0].FileName; classification.Attachment = Convert.ToBase64String(mail.Attachments[0].Body); } return classification; }
/// <summary> /// Figures out the filename of this message part. /// <see cref="FileName"/> property. /// </summary> /// <param name="rawBody">The body that needs to be parsed</param> /// <param name="headers">The headers that should be used from the message</param> /// <param name="defaultName">The default filename to use, if no other could be found</param> /// <returns>The filename found, or the default one if not such filename could be found in the headers</returns> /// <exception cref="ArgumentNullException">if <paramref name="headers"/> is <see langword="null"/></exception> private static string FindFileName(byte[] rawBody, MessageHeader headers, string defaultName) { if (headers == null) throw new ArgumentNullException("headers"); if (headers.ContentDisposition != null && headers.ContentDisposition.FileName != null) return FileManager.RemoveInvalidFileNameChars(headers.ContentDisposition.FileName); var extensionFromContentType = string.Empty; string contentTypeName = null; if (headers.ContentType != null) { extensionFromContentType = MimeType.GetExtensionFromMimeType(headers.ContentType.MediaType); contentTypeName = headers.ContentType.Name; } if (!string.IsNullOrEmpty(headers.ContentDescription)) return FileManager.RemoveInvalidFileNameChars(headers.ContentDescription + extensionFromContentType); if (!string.IsNullOrEmpty(headers.Subject)) return FileManager.RemoveInvalidFileNameChars(headers.Subject) + extensionFromContentType; if (extensionFromContentType.Equals(".eml", StringComparison.OrdinalIgnoreCase)) { try { var message = new Message(rawBody); if (message.Headers != null && !string.IsNullOrEmpty(message.Headers.Subject)) return FileManager.RemoveInvalidFileNameChars(message.Headers.Subject) + extensionFromContentType; } // ReSharper disable once EmptyGeneralCatchClause catch { } } return !string.IsNullOrEmpty(contentTypeName) ? FileManager.RemoveInvalidFileNameChars(contentTypeName) : FileManager.RemoveInvalidFileNameChars(defaultName + extensionFromContentType); }