public void should_process_medial_assist_aid() { CallEmail email = new CallEmail(); email.MessageId = "100"; email.TextBody = " MEDICAL AID; 3464 SPRING CREEK LN ,SPRING_VALLEY ; C42; OLINGER B & W; UNNAMED ST; Map: 794_G_5/C40; Inc# 001072; Tac: ; Air: ; Grd: ; MLPE87 SPV; ---- External Remarks from XSC for XSC:CAXSC:17043020 Status WAI at 02/12/2017-10:25:44 ----<a href=\"http://maps.google.com/?q=37.443783,-121.846332\">Map;</a> X: -121 50.7799 Y: 37 26.6269;"; email.Body = email.TextBody; email.Subject = "Call Email"; string mmId = Guid.NewGuid().ToString(); var priority = (int)CallPriority.High; var call = _callEmailFactory.GenerateCallFromEmailText(CallEmailTypes.CalFireSCU, email, mmId, _dispatchUsers, null, null, null, priority); call.Should().NotBeNull(); call.ReportingUserId.Should().Be(mmId); call.IncidentNumber.Should().Be("001072"); call.SourceIdentifier.Should().Be("100"); call.CallSource.Should().Be((int)CallSources.EmailImport); call.Type.Should().Be("MEDICAL AID"); call.Address.Should().Be("3464 SPRING CREEK LN ,SPRING_VALLEY"); call.NatureOfCall.Should().Be("MEDICAL AID C42 OLINGER B &"); call.Name.Should().Be("MEDICAL AID"); call.MapPage.Should().Be("794_G_5/C40"); call.GeoLocationData.Should().Be("37.443783,-121.846332"); }
public void should_process_elec_haz_email() { CallEmail email = new CallEmail(); email.MessageId = "100"; email.TextBody = "HAZ, ELECTRICAL; 4140 FELTER RD ,SPRING_VALLEY ; C42; PWLD- TREE 12\"; 4800 BLK MARSH RD; Map: 794_J_6/C41; Inc# 000571; Tac: TAC 2; Air: AIR TAC 5; Grd: A/G 3 CDF; SPV; NO TEXT <a href=\"http://maps.google.com/?q=37.440316,-121.835281\">Map;</a> X: -121 50.1168 Y: 37 26.4189; "; email.Body = email.TextBody; email.Subject = "Call Email"; string mmId = Guid.NewGuid().ToString(); var priority = (int)CallPriority.High; var call = _callEmailFactory.GenerateCallFromEmailText(CallEmailTypes.CalFireSCU, email, mmId, _dispatchUsers, null, null, null, priority); call.Should().NotBeNull(); call.ReportingUserId.Should().Be(mmId); call.IncidentNumber.Should().Be("000571"); call.SourceIdentifier.Should().Be("100"); call.CallSource.Should().Be((int)CallSources.EmailImport); call.Type.Should().Be("HAZ, ELECTRICAL"); call.Address.Should().Be("4140 FELTER RD ,SPRING_VALLEY"); call.NatureOfCall.Should().Be("HAZ, ELECTRICAL C42 PWLD- TREE 12\""); call.Name.Should().Be("HAZ, ELECTRICAL"); call.MapPage.Should().Be("794_J_6/C41"); call.GeoLocationData.Should().Be("37.440316,-121.835281"); }
public void should_process_medial_assist_email() { CallEmail email = new CallEmail(); email.MessageId = "100"; email.TextBody = " MED, ASSIST; 3091 CALAVERAS RD ,MILPITAS ; Z201; ; UNNAMED ST; Map: 794_G_5/B40; Inc# 000612; Tac: TAC2; Air: AIR TAC 5; Grd: A/G 3 CDF; SPV; NO TEXT <a href=\"http://maps.google.com/?q=37.448472,-121.846455\">Map;</a> X: -121 50.7873 Y: 37 26.9083; "; email.Body = email.TextBody; email.Subject = "Call Email"; string mmId = Guid.NewGuid().ToString(); var priority = (int)CallPriority.High; var call = _callEmailFactory.GenerateCallFromEmailText(CallEmailTypes.CalFireSCU, email, mmId, _dispatchUsers, null, null, null, priority); call.Should().NotBeNull(); call.ReportingUserId.Should().Be(mmId); call.IncidentNumber.Should().Be("000612"); call.SourceIdentifier.Should().Be("100"); call.CallSource.Should().Be((int)CallSources.EmailImport); call.Type.Should().Be("MED, ASSIST"); call.Address.Should().Be("3091 CALAVERAS RD ,MILPITAS"); call.NatureOfCall.Should().Be("MED, ASSIST Z201"); call.Name.Should().Be("MED, ASSIST"); call.MapPage.Should().Be("794_G_5/B40"); call.GeoLocationData.Should().Be("37.448472,-121.846455"); }
public void should_process_second_alarm() { CallEmail email = new CallEmail(); email.MessageId = "100"; email.TextBody = @"Date: 2018-05-14 10:53:16 Type: 72C01 - Water Rescue/ Sinking Vehicle/Vehicle in Floodwater Location: 5205 51 ST, WHITECOURT Business Name: Subdivision: Common Place: (54.1425, -115.687) Units Responding: WCT FC1, WCT FC2, WCT FC3, WCT Fire, WCT2ndPage" ; email.Body = email.TextBody; email.Subject = "Incident Message"; string mmId = Guid.NewGuid().ToString(); var priority = (int)CallPriority.High; var call = _callEmailFactory.GenerateCallFromEmailText(CallEmailTypes.ParklandCounty2, email, mmId, _dispatchUsers, _department, _activeCalls, _dispatchedUnits, priority); call.Should().NotBeNull(); call.CallId.Should().Be(2); call.DispatchCount.Should().Be(2); call.ReportingUserId.Should().Be("bef090f5-3c18-4a52-9c56-45e597d1c91b"); call.SourceIdentifier.Should().Be("102"); call.CallSource.Should().Be((int)CallSources.EmailImport); call.Priority.Should().Be(3); call.LoggedOn.Should().BeCloseTo(new DateTime(2018, 5, 14, 15, 53, 16, DateTimeKind.Utc)); call.Name.Should().Be("72C01 - Water Rescue/ Sinking Vehicle/Vehicle in Floodwater"); call.GeoLocationData.Should().Be("54.1425, -115.687"); }
public void should_work_with_gps_coordinates_commas() { CallEmail email = new CallEmail(); email.MessageId = "100"; email.TextBody = "(29), Medical/EMS, 39.14086268299356,-119.7583809782715,// MEDICAL ALARM SHOWS UNIT IS VACANT NO PX NUMBER FOR ACCOUNT."; email.Subject = "Call Email"; string mmId = Guid.NewGuid().ToString(); var priority = (int)CallPriority.High; var call = _callEmailFactory.GenerateCallFromEmailText(CallEmailTypes.HancockCounty, email, mmId, _dispatchUsers, null, null, null, priority); call.Should().NotBeNull(); call.ReportingUserId.Should().Be(mmId); call.IncidentNumber.Should().Be("29"); call.SourceIdentifier.Should().Be("100"); call.CallSource.Should().Be((int)CallSources.EmailImport); call.Type.Should().Be("Medical/EMS"); call.Address.Should().BeNullOrWhiteSpace(); call.GeoLocationData.Should().Be("39.14086268299356,-119.7583809782715"); call.NatureOfCall.Should().Be("MEDICAL ALARM SHOWS UNIT IS VACANT NO PX NUMBER FOR ACCOUNT."); call.Name.Should().Be("29-Medical/EMS"); }
public Call GenerateCall(CallEmail email, string managingUser, List<IdentityUser> users, Department department, List<Call> activeCalls, List<Unit> units, int priority) { if (email == null) return null; if (String.IsNullOrEmpty(email.Body)) return null; if (String.IsNullOrEmpty(email.Subject)) return null; Call c = new Call(); c.Notes = email.Subject + " " + email.Body; c.NatureOfCall = email.Body; c.Name = "Call Email Import"; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection<CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; c.Address = email.Subject.Trim(); foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return c; }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } if (!email.Subject.ToLower().Contains("page")) { return(null); } Call c = new Call(); c.Notes = email.Subject + " " + email.Body; c.NatureOfCall = email.Subject + " " + email.Body; c.Name = email.Subject; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; if (email.DispatchAudio != null) { c.Attachments = new Collection <CallAttachment>(); CallAttachment ca = new CallAttachment(); ca.FileName = email.DispatchAudioFileName; ca.Data = email.DispatchAudio; ca.CallAttachmentType = (int)CallAttachmentTypes.DispatchAudio; c.Attachments.Add(ca); } foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public void should_work_for_department_7966_withprios() { CallEmail email = new CallEmail(); email.MessageId = "100"; email.TextBody = @"CALL: Medical Unknown Problems ADDR: -76.0254669,41.513334 ADDR1: 555 MAIN ST ID: 2020-000698745-MED Date/Time:Date/Time: 1/1/2020 3:19:00 AM MAP: http://www.google.com/maps/place/41.513334,-76.0254669 UNITS: MEDIC01, NARR: 55 YOM NARR: CONSCIOUS / WILL NOT RESPOND NARR: NO OTHER SYMPTOMS OF COVID NARR: HAS COPD NARR: 1057 ENR TO SCENE NARR: 1057 ON SCENE NARR: DISCONTINUE TIME STAMPS" ; email.Subject = "ACTIVE 9-1-1"; string mmId = Guid.NewGuid().ToString(); var priority = (int)CallPriority.High; var department = new Department(); department.DepartmentId = 7966; var prios = new List <DepartmentCallPriority>(); prios.Add(new DepartmentCallPriority { DepartmentCallPriorityId = 500, Name = "MVA" }); prios.Add(new DepartmentCallPriority { DepartmentCallPriorityId = 501, Name = "MEDICAL" }); prios.Add(new DepartmentCallPriority { DepartmentCallPriorityId = 502, Name = "Unknown" }); var call = _callEmailFactory.GenerateCallFromEmailText(CallEmailTypes.Active911, email, mmId, _dispatchUsers, department, null, null, priority, prios); call.Should().NotBeNull(); call.ReportingUserId.Should().Be(mmId); call.IncidentNumber.Should().Be("2020-000698745-MED"); call.SourceIdentifier.Should().Be("100"); call.CallSource.Should().Be((int)CallSources.EmailImport); //call.Type.Should().Be("Medical/EMS"); call.Address.Should().Be("555 MAIN ST"); call.NatureOfCall.Should().NotBeNull(); call.Notes.Should().BeNull(); call.Name.Should().Be("Medical Unknown Problems"); call.Type.Should().Be("Medical"); call.Priority.Should().Be(501); }
public Call GenerateCallFromEmailText(CallEmailTypes type, CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority, List <DepartmentCallPriority> activePriorities) { Call call = null; try { call = _templates[(int)type].GenerateCall(email, managingUser, users, department, activeCalls, units, priority, activePriorities); } catch (Exception ex) { Framework.Logging.LogException(ex, string.Format("Email Text: {0}", email.Body)); } return(call); }
public void should_not_process_close() { CallEmail email = new CallEmail(); email.MessageId = "100"; email.TextBody = "RES: SPV; RES: SPV; CLOSE: Inc# 001072; MEDICAL AID; 3464 SPRING CREEK LN ,SPRING_VALLEY ; C42;DSP: 2-12-10:26; AIQ: 2-12-11:37; "; email.Body = email.TextBody; email.Subject = "Call Email"; string mmId = Guid.NewGuid().ToString(); var priority = (int)CallPriority.High; var call = _callEmailFactory.GenerateCallFromEmailText(CallEmailTypes.CalFireSCU, email, mmId, _dispatchUsers, null, null, null, priority); call.Should().BeNull(); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } Call c = new Call(); c.Notes = email.Body; string[] data = email.Body.Split(char.Parse(";")); c.IncidentNumber = data[0].Replace("Inc# ", "").Trim(); c.Type = data[1].Trim(); try { int end = data[6].IndexOf(">Map"); c.GeoLocationData = data[6].Substring(37, end - 38); } catch { } c.NatureOfCall = data[1].Trim() + " " + data[7]; c.Address = data[2].Trim(); c.Name = data[1].Trim() + " " + data[7]; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority, List <DepartmentCallPriority> activePriorities) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } string[] data = email.Body.Split(char.Parse("/")); Call c = new Call(); c.Notes = email.Subject + " " + email.Body; c.NatureOfCall = email.Body; c.Name = email.Subject; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; if (data != null && data.Length > 0) { c.Name = data[2]; c.Address = data[3]; } foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public void should_work_with_address_with_commas() { CallEmail email = new CallEmail(); email.MessageId = "100"; email.TextBody = "(29), Medical/EMS, 521 W MAIN CROSS ST # 108, ARLINGTON, OH 45814,// MEDICAL ALARM SHOWS UNIT IS VACANT NO PX NUMBER FOR ACCOUNT."; email.Subject = "Call Email"; string mmId = Guid.NewGuid().ToString(); var priority = (int)CallPriority.High; var call = _callEmailFactory.GenerateCallFromEmailText(CallEmailTypes.HancockCounty, email, mmId, _dispatchUsers, null, null, null, priority); call.Should().NotBeNull(); call.ReportingUserId.Should().Be(mmId); call.IncidentNumber.Should().Be("29"); call.SourceIdentifier.Should().Be("100"); call.CallSource.Should().Be((int)CallSources.EmailImport); call.Type.Should().Be("Medical/EMS"); call.Address.Should().Be("521 W MAIN CROSS ST # 108, ARLINGTON, OH 45814"); call.NatureOfCall.Should().Be("MEDICAL ALARM SHOWS UNIT IS VACANT NO PX NUMBER FOR ACCOUNT."); call.Name.Should().Be("29-Medical/EMS"); }
public Call GenerateCallFromEmail(int type, CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { return(_callEmailFactory.GenerateCallFromEmailText((CallEmailTypes)type, email, managingUser, users, department, activeCalls, units, priority)); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } if (!email.Subject.Contains("Parkland County Incident") && !email.Subject.Contains("Incident Message")) { return(null); } bool is2ndPage = false; string priorityChar = null; DateTime callTimeUtc = DateTime.UtcNow; var c = new Call(); c.Notes = email.Body; try { var data = new List <string>(); string[] rawData = email.Body.Split(new string[] { "\r\n", "\r\n\r\n" }, StringSplitOptions.None); if (rawData != null && rawData.Any()) { foreach (string s in rawData) { if (!string.IsNullOrWhiteSpace(s)) { data.Add(s); } } if (data.Count > 0) { c.Name = data[1].Trim().Replace("Type: ", ""); var priorityString = c.Name.Substring(0, c.Name.IndexOf(char.Parse("-"))).Trim(); priorityChar = Regex.Replace(priorityString, @"\d", "").Trim(); TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById(department.TimeZone); callTimeUtc = new DateTimeOffset(DateTime.Parse(data[0].Replace("Date:", "").Trim()), timeZone.BaseUtcOffset).UtcDateTime; is2ndPage = c.Notes.Contains("WCT2ndPage"); try { var location = data.FirstOrDefault(x => x.StartsWith("Location:")); if (!String.IsNullOrWhiteSpace(location)) { c.Address = location.Replace("//", "").Replace("Business Name:", ""); } var coordinates = data.FirstOrDefault(x => x.Contains("(") && x.Contains(")")); if (!String.IsNullOrWhiteSpace(coordinates)) { coordinates = coordinates.Replace("Common Place:", ""); coordinates = coordinates.Trim(); c.GeoLocationData = coordinates.Replace("(", "").Replace(")", ""); } } catch { } } } else { c.Name = "Call Import Type: Unknown"; } } catch { c.Name = "Call Import Type: Unknown"; } c.NatureOfCall = email.Body; c.LoggedOn = callTimeUtc; c.Priority = PriorityMapping(priorityChar, is2ndPage, priority); c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.UnitDispatches = new Collection <CallDispatchUnit>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } if (units != null && units.Any()) { foreach (var unit in units) { var ud = new CallDispatchUnit(); ud.UnitId = unit.UnitId; ud.LastDispatchedOn = DateTime.UtcNow; c.UnitDispatches.Add(ud); } } // Search for an active call if (activeCalls != null && activeCalls.Any()) { var activeCall = activeCalls.FirstOrDefault(x => x.Name == c.Name && x.LoggedOn == c.LoggedOn); if (activeCall != null) { activeCall.Priority = c.Priority; activeCall.Notes = c.Notes; activeCall.LastDispatchedOn = DateTime.UtcNow; activeCall.DispatchCount++; return(activeCall); } } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body) && String.IsNullOrWhiteSpace(email.TextBody)) { return(null); } string body = String.Empty; if (!String.IsNullOrWhiteSpace(email.TextBody)) { body = email.TextBody; } else { body = email.Body; } body = body.Replace("-- Confidentiality Notice --", ""); body = body.Replace( "This email message, including all the attachments, is for the sole use of the intended recipient(s) and contains confidential information. Unauthorized use or disclosure is prohibited.", ""); body = body.Replace( "If you are not the intended recipient, you may not use, disclose, copy or disseminate this information.", ""); body = body.Replace( "If you are not the intended recipient, please contact the sender immediately by reply email and destroy all copies of the original message,", ""); body = body.Replace( "including attachments.", ""); body = body.Trim(); var c = new Call(); c.Notes = email.TextBody; if (String.IsNullOrWhiteSpace(c.Notes)) { c.Notes = email.Body; } string[] data = body.Split(char.Parse(":")); c.IncidentNumber = data[1].Replace(" L", "").Trim(); c.Type = data[3].Replace(" X", "").Trim().Replace("/", ""); c.Address = data[2].Replace(" T", "").Trim().Replace("/", ""); c.NatureOfCall = data[4].Trim(); c.Name = c.Type + " " + c.NatureOfCall; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } Call c = new Call(); c.Notes = email.Subject + " " + email.Body; c.Name = email.Subject; string[] data = email.Body.Split(char.Parse(",")); if (data.Length >= 1) { int tryPriority; if (int.TryParse(data[0], out tryPriority)) { c.Priority = tryPriority; } } else { c.Priority = (int)CallPriority.High; } if (data.Length >= 2) { if (data[1].Length > 3) { c.NatureOfCall = data[1]; } } else { c.NatureOfCall = email.Body; } if (data.Length >= 3) { if (data[2].Length > 3) { string address = String.Empty; if (!data[2].Contains("United Kingdom")) { address = data[2] + "United Kingdom"; } c.Address = address; } } c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; if (email.DispatchAudio != null) { c.Attachments = new Collection <CallAttachment>(); CallAttachment ca = new CallAttachment(); ca.FileName = email.DispatchAudioFileName; ca.Data = email.DispatchAudio; ca.CallAttachmentType = (int)CallAttachmentTypes.DispatchAudio; c.Attachments.Add(ca); } foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } if (!email.Subject.Contains("Parkland County Incident") && !email.Subject.Contains("Incident Message")) { return(null); } var c = new Call(); c.Notes = email.Body; try { var data = new List <string>(); string[] rawData = email.Body.Split(new string[] { "\r\n", "\r\n\r\n" }, StringSplitOptions.None); if (rawData != null && rawData.Any()) { foreach (string s in rawData) { if (!string.IsNullOrWhiteSpace(s)) { data.Add(s); } } if (data.Count > 0) { c.Name = data[1].Trim().Replace("Type: ", ""); try { var location = data.FirstOrDefault(x => x.StartsWith("Location:")); if (!String.IsNullOrWhiteSpace(location)) { c.Address = location.Replace("//", "").Replace("Business Name:", ""); } var coordinates = data.FirstOrDefault(x => x.Contains("(") && x.Contains(")")); if (!String.IsNullOrWhiteSpace(coordinates)) { coordinates = coordinates.Replace("Common Place:", ""); coordinates = coordinates.Trim(); c.GeoLocationData = coordinates.Replace("(", "").Replace(")", ""); } } catch { } } } else { c.Name = "Call Import Type: Unknown"; } } catch { c.Name = "Call Import Type: Unknown"; } c.NatureOfCall = email.Body; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } string[] data = email.Body.Split(char.Parse("|")); Call c = new Call(); c.Notes = email.Subject + " " + email.Body; if (data != null && data.Length >= 4) { c.NatureOfCall = data[3]; } else { c.NatureOfCall = email.Subject + " " + email.Body; } if (data != null && data.Length >= 1) { c.Name = data[0]; } c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; if (data != null && data.Length > 3) { var geoData = data[2].Replace("[LONGLAT:", "").Replace("] - 1:", ""); if (!String.IsNullOrWhiteSpace(geoData)) { var geoDataArray = geoData.Split(char.Parse(",")); if (geoDataArray != null && geoDataArray.Length == 2) { c.GeoLocationData = $"{geoDataArray[1]}.{geoDataArray[0]}"; } } } foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } if (!email.Subject.Contains("Perform Page")) { return(null); } Call c = new Call(); c.Notes = email.Subject + " " + email.Body; c.NatureOfCall = email.Body; List <string> data = new List <string>(); string[] rawData = email.Body.Split(new string[] { "\r\n", "\r\n\r\n" }, StringSplitOptions.None); foreach (string s in rawData) { if (!string.IsNullOrWhiteSpace(s)) { data.Add(s); } } if (data.Count >= 1) { c.Name = data[0]; } else { c.Name = email.Subject; } if (data.Count == 5) { string firstLine = string.Empty; if (data[1].ToUpper().Contains("AND")) { string[] firstLineParts = data[1].Split(new string[] { "AND" }, StringSplitOptions.None); if (!string.IsNullOrWhiteSpace(firstLineParts[0])) { firstLine = firstLineParts[0]; } } else if (data[1].ToUpper().Contains("/")) { string[] firstLineParts = data[1].Split(new string[] { "/" }, StringSplitOptions.None); if (!string.IsNullOrWhiteSpace(firstLineParts[0])) { firstLine = firstLineParts[0]; } } else { firstLine = data[1]; } c.Address = string.Format("{0} {1}", firstLine, data[2]); } else if (data.Count == 6) { c.Address = string.Format("{0} {1}", data[2], data[3]); } c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; if (email.DispatchAudio != null) { c.Attachments = new Collection <CallAttachment>(); CallAttachment ca = new CallAttachment(); ca.FileName = email.DispatchAudioFileName; ca.Data = email.DispatchAudio; ca.CallAttachmentType = (int)CallAttachmentTypes.DispatchAudio; c.Attachments.Add(ca); } foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority, List <DepartmentCallPriority> activePriorities) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body) && String.IsNullOrWhiteSpace(email.TextBody)) { return(null); } string body = String.Empty; if (!String.IsNullOrWhiteSpace(email.TextBody)) { body = email.TextBody; } else { body = email.Body; } var c = new Call(); c.Notes = email.TextBody; if (String.IsNullOrWhiteSpace(c.Notes)) { c.Notes = email.Body; } string[] data = body.Split(char.Parse(",")); if (data == null || data.Length <= 2) { return(null); } c.IncidentNumber = data[0].Replace("(", "").Replace(")", "").Trim(); c.Type = data[1].Trim(); string address = String.Empty; string coordinates = String.Empty; int gpsCount = 0; for (int i = 2; i < data.Length; i++) { if (data[i].Contains("//")) { break; } decimal myDec; if (!decimal.TryParse(data[i].Trim(), out myDec)) { if (String.IsNullOrWhiteSpace(address)) { address = data[i].Trim(); } else { address += string.Format(", {0}", data[i].Trim()); } } else { if (gpsCount >= 2) { break; } if (String.IsNullOrWhiteSpace(coordinates)) { coordinates = data[i].Trim(); } else { coordinates += string.Format(",{0}", data[i].Trim()); } gpsCount++; } } if (!String.IsNullOrWhiteSpace(address)) { c.Address = address.Trim(); } if (!String.IsNullOrWhiteSpace(coordinates)) { c.GeoLocationData = coordinates.Trim(); } c.NatureOfCall = data[data.Length - 1].Replace("//", "").Trim(); c.Name = string.Format("{0}-{1}", c.IncidentNumber, c.Type); c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority, List <DepartmentCallPriority> activePriorities) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } Call c = new Call(); c.Notes = email.Body; c.Name = email.Subject; int nonEmptyLineCount = 0; string[] rawData = email.Body.Split(new string[] { "\r\n", "\r\n\r\n" }, StringSplitOptions.None); foreach (var line in rawData) { if (line != null && !String.IsNullOrWhiteSpace(line)) { nonEmptyLineCount++; switch (nonEmptyLineCount) { case 1: //c.Name = line.Trim(); c.NatureOfCall = line.Trim(); break; case 2: // Address //c.Name = $"{c.Name} {line}"; c.NatureOfCall = c.NatureOfCall + " " + line; break; case 3: // Map and Radio Channel break; case 4: // Cross Street break; case 5: // Cross Street 2 break; } } } c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body) && String.IsNullOrEmpty(email.TextBody)) { return(null); } string emailBody = email.Body; if (String.IsNullOrWhiteSpace(email.Body)) { emailBody = email.TextBody; } if (emailBody.Contains("CLOSE: Inc#")) { return(null); } Call c = new Call(); c.Notes = emailBody; string[] data = emailBody.Split(char.Parse(";")); if (data == null || data.Length <= 2) { return(null); } var incidentNumber = data.FirstOrDefault(x => x.Contains("Inc#")); if (incidentNumber != null) { c.IncidentNumber = incidentNumber.Replace("Inc# ", "").Trim(); } c.Type = data[0].Trim(); try { var mapSection = data.FirstOrDefault(x => x.Contains("?q=")); if (mapSection != null) { int start = mapSection.IndexOf("?q="); int end = mapSection.IndexOf(">Map"); c.GeoLocationData = mapSection.Substring(start + 3, (end - start - 4)); } } catch { } c.NatureOfCall = data[0].Trim() + " " + data[2].Trim() + " " + data[3].Trim(); c.NatureOfCall = c.NatureOfCall.Trim(); c.Address = data[1].Trim(); c.Name = data[0].Trim(); c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; var mapPage = data.FirstOrDefault(x => x.Contains("Map:")); if (mapPage != null) { c.MapPage = mapPage.Replace("Map: ", "").Trim(); } foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority, List <DepartmentCallPriority> activePriorities) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.TextBody)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } if (!email.Subject.ToLower().Contains("active")) { return(null); } Call c = new Call(); // For 7966 if (department == null || department.DepartmentId != 7966) { c.Notes = email.TextBody; } c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; string[] lines = email.TextBody.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); var sb = new StringBuilder(); sb.Append("<p>"); foreach (var line in lines) { var trimmedLine = line.Trim(); if (!String.IsNullOrWhiteSpace(trimmedLine)) { if (trimmedLine.ToLower().StartsWith("call:")) { c.Name = trimmedLine.Replace("CALL:", "").Trim(); sb.Append(trimmedLine + "</br>"); if (department != null && department.DepartmentId == 7966) { string[] typePrioline = c.Name.Split(new[] { " " }, StringSplitOptions.None); c.Type = typePrioline[0].Trim(); c.Priority = ParseCallPriority(typePrioline[0].Trim(), priority, activePriorities); } } else if (trimmedLine.ToLower().StartsWith("addr:")) { //c.GeoLocationData = trimmedLine.Replace("ADDR:", "").Trim(); sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.ToLower().StartsWith("addr1:")) { c.Address = trimmedLine.Replace("ADDR1:", "").Trim(); sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.ToLower().StartsWith("id:")) { c.IncidentNumber = trimmedLine.Replace("ID:", "").Trim(); c.ExternalIdentifier = c.IncidentNumber; if (department != null && department.DepartmentId == 7966) { c.ReferenceNumber = ParseIncidentNumber(trimmedLine); } sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.ToLower().StartsWith("map:")) { c.GeoLocationData = trimmedLine.Replace("MAP:", "").Replace("http://www.google.com/maps/place/", "").Trim(); } else if (trimmedLine.ToLower().StartsWith("date/time:")) { sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.ToLower().StartsWith("date/time:")) { sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.ToLower().StartsWith("narr:")) { sb.Append(trimmedLine.Replace("NARR:", "").Trim() + "</br>"); } } } sb.Append("</p>"); c.NatureOfCall = sb.ToString(); foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } // Search for an active call if (activeCalls != null && activeCalls.Any()) { var activeCall = activeCalls.FirstOrDefault(x => x.IncidentNumber == c.IncidentNumber); if (activeCall != null) { if (department == null || department.DepartmentId != 7966) { activeCall.Notes = c.Notes; } else { c.NatureOfCall = sb.ToString(); } activeCall.LastDispatchedOn = DateTime.UtcNow; return(activeCall); } } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority, List <DepartmentCallPriority> activePriorities) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } //if (String.IsNullOrEmpty(email.Subject)) // return null; Call c = new Call(); c.Notes = email.Subject + " " + email.Body; c.NatureOfCall = email.Body; c.Name = "Call Email Import"; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; string[] rawData = email.Body.Split(new string[] { "\r\n", "\r\n\r\n" }, StringSplitOptions.None); if (rawData != null && rawData.Any()) { foreach (string s in rawData) { if (!string.IsNullOrWhiteSpace(s) && s.StartsWith("La", StringComparison.InvariantCultureIgnoreCase)) { string[] geoData = s.Split(new string[] { " " }, StringSplitOptions.None); if (geoData != null && geoData.Length == 2) { var latDMS = geoData[0].Replace(" grader ", ",").Replace("La = ", "").Replace("'N", "").Trim(); var lonDMS = geoData[1].Replace(" grader ", ",").Replace("Lo = ", "").Replace("'E", "").Trim(); if (!String.IsNullOrWhiteSpace(latDMS) && !String.IsNullOrWhiteSpace(lonDMS)) { string[] latValues = latDMS.Split(new string[] { "," }, StringSplitOptions.None); string[] lonValues = lonDMS.Split(new string[] { "," }, StringSplitOptions.None); double lat = 0; if (latValues != null && latValues.Length == 3) { lat = LocationHelpers.ConvertDegreesToDecimal(latValues[0].Trim(), latValues[1].Trim(), latValues[2].Trim()); } double lon = 0; if (lonValues != null && lonValues.Length == 3) { lon = LocationHelpers.ConvertDegreesToDecimal(lonValues[0].Trim(), lonValues[1].Trim(), lonValues[2].Trim()); } if (lat != 0 && lon != 0) { c.GeoLocationData = $"{lat},{lon}"; } } } } } } foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority, List <DepartmentCallPriority> activePriorities) { //ID | TYPE | PRIORITY | ADDRESS | MAPPAGE | NATURE | NOTES if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } Call c = new Call(); c.Notes = email.Body; string[] data = email.Body.Split(char.Parse("|")); if (data.Any() && data.Length >= 5) { if (!string.IsNullOrEmpty(data[0])) { c.IncidentNumber = data[0].Trim(); } if (!string.IsNullOrEmpty(data[1])) { c.Type = data[1].Trim(); } if (string.IsNullOrEmpty(data[2])) { int prio; if (int.TryParse(data[2], out prio)) { c.Priority = prio; } else { c.Priority = priority; } } else { c.Priority = priority; } if (!string.IsNullOrEmpty(data[4])) { c.MapPage = data[4]; } c.NatureOfCall = data[5]; c.Address = data[3]; StringBuilder title = new StringBuilder(); title.Append("Email Call "); title.Append(((CallPriority)c.Priority).ToString()); title.Append(" "); if (!string.IsNullOrEmpty(c.Type)) { title.Append(c.Type); title.Append(" "); } if (!string.IsNullOrEmpty(c.IncidentNumber)) { title.Append(c.IncidentNumber); title.Append(" "); } c.Name = title.ToString(); } else { c.Name = email.Subject; c.NatureOfCall = email.Body; c.Notes = "WARNING: FALLBACK RESGRID EMAIL IMPORT! THIS EMAIL MAY NOT BE THE CORRECT FORMAT FOR THE RESGRID EMAIL TEMPLATE. CONTACT SUPPORT IF THE EMAIL AND TEMPLATE ARE CORRECT." + email.Body; } c.LoggedOn = DateTime.UtcNow; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority, List <DepartmentCallPriority> activePriorities) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } string[] lines = email.TextBody.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); Call c = new Call(); c.Notes = email.TextBody; c.Name = email.Subject.Replace("Automatic R&R Notification:", "").Replace("Fw:", "").Replace("FW:", "").Replace("fw:", "").Trim(); c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; var sb = new StringBuilder(); sb.Append("<p>"); foreach (var line in lines) { var trimmedLine = line.Trim(); if (!String.IsNullOrWhiteSpace(trimmedLine)) { if (trimmedLine.StartsWith("Address:")) { c.Address = trimmedLine.Replace("Address:", "").Trim(); sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.StartsWith("Common Name:")) { if (trimmedLine.Length > 12) { sb.Append(trimmedLine + "</br>"); } } else if (trimmedLine.StartsWith("Cross Streets:")) { sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.StartsWith("https://www.google.com")) { sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.StartsWith("Call Date/Time:")) { sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.StartsWith("Call Type:")) { sb.Append(trimmedLine + "</br>"); string[] typePrioline = trimmedLine.Split(new[] { ", ," }, StringSplitOptions.None); if (typePrioline.Length == 2) { c.Type = typePrioline[0].Replace("Call Type:", "").Replace(", ,", "").Trim(); c.Priority = ParseCallPriority(typePrioline[1].Replace("Call Priority:", "").Replace(", ,", "").Trim(), priority, activePriorities); } } else if (trimmedLine.StartsWith("Fire Area:")) { sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.StartsWith("Incident Numbers:")) { sb.Append(trimmedLine + "</br>"); c.IncidentNumber = ParseIncidentNumber(trimmedLine); } else if (trimmedLine.StartsWith("Units:")) { sb.Append(trimmedLine + "</br>"); } } } sb.Append("</p>"); c.NatureOfCall = sb.ToString(); if (users != null && users.Any()) { foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } } // Search for an active call if (activeCalls != null && activeCalls.Any()) { var activeCall = activeCalls.FirstOrDefault(x => x.IncidentNumber == c.IncidentNumber); if (activeCall != null) { activeCall.Notes = c.Notes; activeCall.LastDispatchedOn = DateTime.UtcNow; return(activeCall); } } return(c); }
public HttpResponseMessage Receive(PostmarkInboundMessage message) { if (message != null) { try { var mailMessage = new MimeMessage(); if (message.FromFull != null && !String.IsNullOrWhiteSpace(message.FromFull.Email) && message.FromFull.Email.Trim() == "*****@*****.**") { return(new HttpResponseMessage(HttpStatusCode.Created)); } if (message.FromFull != null && !String.IsNullOrWhiteSpace(message.FromFull.Email) && !String.IsNullOrWhiteSpace(message.FromFull.Name)) { mailMessage.From.Add(new MailboxAddress(message.FromFull.Name.Trim(), message.FromFull.Email.Trim())); } else { mailMessage.From.Add(new MailboxAddress("Inbound Email Dispatch", "*****@*****.**")); } if (!String.IsNullOrWhiteSpace(message.Subject)) { mailMessage.Subject = message.Subject; } else { mailMessage.Subject = "Dispatch Email"; } var builder = new BodyBuilder(); if (!String.IsNullOrWhiteSpace(message.HtmlBody)) { builder.HtmlBody = HttpUtility.HtmlDecode(message.HtmlBody); } if (!String.IsNullOrWhiteSpace(message.TextBody)) { builder.TextBody = message.TextBody; } int type = 0; // 1 = dispatch // 2 = email list // 3 = group dispatch // 4 = group message string emailAddress = String.Empty; string bounceEmail = String.Empty; string name = String.Empty; #region Trying to Find What type of email this is foreach (var email in message.ToFull) { if (StringHelpers.ValidateEmail(email.Email)) { if (email.Email.Contains($"@{Config.InboundEmailConfig.DispatchDomain}") || email.Email.Contains($"@{Config.InboundEmailConfig.DispatchTestDomain}")) { type = 1; if (email.Email.Contains($"@{Config.InboundEmailConfig.DispatchDomain}")) { emailAddress = email.Email.Replace($"@{Config.InboundEmailConfig.DispatchDomain}", ""); } else { emailAddress = email.Email.Replace($"@{Config.InboundEmailConfig.DispatchTestDomain}", ""); } name = email.Name; mailMessage.To.Clear(); mailMessage.To.Add(new MailboxAddress(email.Name, email.Email)); break; } else if (email.Email.Contains($"@{Config.InboundEmailConfig.ListsDomain}") || email.Email.Contains($"@{Config.InboundEmailConfig.ListsTestDomain}")) { type = 2; if (email.Email.Contains($"@{Config.InboundEmailConfig.ListsDomain}")) { emailAddress = email.Email.Replace($"@{Config.InboundEmailConfig.ListsDomain}", ""); } else { emailAddress = email.Email.Replace($"@{Config.InboundEmailConfig.ListsTestDomain}", ""); } if (emailAddress.Contains("+") && emailAddress.Contains("=")) { var tempBounceEmail = emailAddress.Substring(emailAddress.IndexOf("+") + 1); bounceEmail = tempBounceEmail.Replace("=", "@"); emailAddress = emailAddress.Replace(tempBounceEmail, ""); emailAddress = emailAddress.Replace("+", ""); } name = email.Name; mailMessage.To.Clear(); mailMessage.To.Add(new MailboxAddress(email.Name, email.Email)); break; } else if (email.Email.Contains($"@{Config.InboundEmailConfig.GroupsDomain}") || email.Email.Contains($"@{Config.InboundEmailConfig.GroupsTestDomain}")) { type = 3; if (email.Email.Contains($"@{Config.InboundEmailConfig.GroupsDomain}")) { emailAddress = email.Email.Replace($"@{Config.InboundEmailConfig.GroupsDomain}", ""); } else { emailAddress = email.Email.Replace($"@{Config.InboundEmailConfig.GroupsTestDomain}", ""); } name = email.Name; mailMessage.To.Clear(); mailMessage.To.Add(new MailboxAddress(email.Name, email.Email)); break; } else if (email.Email.Contains($"@{Config.InboundEmailConfig.GroupMessageDomain}") || email.Email.Contains($"@{Config.InboundEmailConfig.GroupTestMessageDomain}")) { type = 4; if (email.Email.Contains($"@{Config.InboundEmailConfig.GroupMessageDomain}")) { emailAddress = email.Email.Replace($"@{Config.InboundEmailConfig.GroupMessageDomain}", ""); } else { emailAddress = email.Email.Replace($"@{Config.InboundEmailConfig.GroupTestMessageDomain}", ""); } name = email.Name; mailMessage.To.Clear(); mailMessage.To.Add(new MailboxAddress(email.Name, email.Email)); break; } } } // Some providers aren't putting email address in the To line, process the CC line if (type == 0) { foreach (var email in message.CcFull) { if (StringHelpers.ValidateEmail(email.Email)) { var proccedEmailInfo = ProcessEmailAddress(email.Email); if (proccedEmailInfo.Item1 > 0) { type = proccedEmailInfo.Item1; emailAddress = proccedEmailInfo.Item2; mailMessage.To.Clear(); mailMessage.To.Add(new MailboxAddress(email.Name, email.Email)); } } } } // If To and CC didn't work, try the header. if (type == 0) { try { if (message.Headers != null && message.Headers.Count > 0) { var header = message.Headers.FirstOrDefault(x => x.Name == "Received-SPF"); if (header != null) { var lastValue = header.Value.LastIndexOf(char.Parse("=")); var newEmail = header.Value.Substring(lastValue + 1, (header.Value.Length - (lastValue + 1))); newEmail = newEmail.Trim(); if (StringHelpers.ValidateEmail(newEmail)) { emailAddress = newEmail; var proccedEmailInfo = ProcessEmailAddress(newEmail); type = proccedEmailInfo.Item1; emailAddress = proccedEmailInfo.Item2; mailMessage.To.Clear(); mailMessage.To.Add(new MailboxAddress("Email Importer", newEmail)); } } } } catch (Exception ex) { Logging.LogException(ex); } } #endregion Trying to Find What type of email this is if (type == 1) // Dispatch { #region Dispatch Email var departmentId = _departmentSettingsService.GetDepartmentIdForDispatchEmail(emailAddress); if (departmentId.HasValue) { try { var emailSettings = _departmentsService.GetDepartmentEmailSettings(departmentId.Value); List <IdentityUser> departmentUsers = _departmentsService.GetAllUsersForDepartment(departmentId.Value, true); var callEmail = new CallEmail(); if (!String.IsNullOrWhiteSpace(message.Subject)) { callEmail.Subject = message.Subject; } else { callEmail.Subject = "Dispatch Email"; } if (!String.IsNullOrWhiteSpace(message.HtmlBody)) { callEmail.Body = HttpUtility.HtmlDecode(message.HtmlBody); } else { callEmail.Body = message.TextBody; } callEmail.TextBody = message.TextBody; foreach (var attachment in message.Attachments) { try { if (Convert.ToInt32(attachment.ContentLength) > 0) { if (attachment.Name.Contains(".mp3") || attachment.Name.Contains(".amr")) { byte[] filebytes = Convert.FromBase64String(attachment.Content); callEmail.DispatchAudioFileName = attachment.Name; callEmail.DispatchAudio = filebytes; } } } catch { } } if (emailSettings == null) { emailSettings = new DepartmentCallEmail(); emailSettings.FormatType = (int)CallEmailTypes.Generic; emailSettings.DepartmentId = departmentId.Value; emailSettings.Department = _departmentsService.GetDepartmentById(departmentId.Value, false); } else if (emailSettings.Department == null) { emailSettings.Department = _departmentsService.GetDepartmentById(departmentId.Value); } var activeCalls = _callsService.GetLatest10ActiveCallsByDepartment(emailSettings.Department.DepartmentId); var units = _unitsService.GetUnitsForDepartment(emailSettings.Department.DepartmentId); var priorities = _callsService.GetActiveCallPrioritesForDepartment(emailSettings.Department.DepartmentId); int defaultPriority = (int)CallPriority.High; if (priorities != null && priorities.Any()) { var defaultPrio = priorities.FirstOrDefault(x => x.IsDefault && x.IsDeleted == false); if (defaultPrio != null) { defaultPriority = defaultPrio.DepartmentCallPriorityId; } } var call = _callsService.GenerateCallFromEmail(emailSettings.FormatType, callEmail, emailSettings.Department.ManagingUserId, departmentUsers, emailSettings.Department, activeCalls, units, defaultPriority); if (call != null) { call.DepartmentId = departmentId.Value; var savedCall = _callsService.SaveCall(call); var cqi = new CallQueueItem(); cqi.Call = savedCall; cqi.Profiles = _userProfileService.GetAllProfilesForDepartment(call.DepartmentId).Select(x => x.Value).ToList(); cqi.DepartmentTextNumber = _departmentSettingsService.GetTextToCallNumberForDepartment(cqi.Call.DepartmentId); _queueService.EnqueueCallBroadcast(cqi); return(new HttpResponseMessage(HttpStatusCode.Created)); } } catch (Exception ex) { Logging.LogException(ex); return(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } #endregion Dispatch } else if (type == 2) // Email List { #region Distribution Email var list = _distributionListsService.GetDistributionListByAddress(emailAddress); if (list != null) { if (String.IsNullOrWhiteSpace(bounceEmail)) { try { List <Model.File> files = new List <Model.File>(); try { if (message.Attachments != null && message.Attachments.Any()) { foreach (var attachment in message.Attachments) { if (Convert.ToInt32(attachment.ContentLength) > 0) { Model.File file = new Model.File(); byte[] filebytes = Convert.FromBase64String(attachment.Content); file.Data = filebytes; file.FileName = attachment.Name; file.DepartmentId = list.DepartmentId; file.ContentId = attachment.ContentID; file.FileType = attachment.ContentType; file.Timestamp = DateTime.UtcNow; files.Add(_fileService.SaveFile(file)); } } } } catch { } var dlqi = new DistributionListQueueItem(); dlqi.List = list; dlqi.Users = _departmentsService.GetAllUsersForDepartment(list.DepartmentId); if (files != null && files.Any()) { dlqi.FileIds = new List <int>(); dlqi.FileIds.AddRange(files.Select(x => x.FileId).ToList()); } dlqi.Message = new InboundMessage(); dlqi.Message.Attachments = new List <InboundMessageAttachment>(); if (message.FromFull != null && !String.IsNullOrWhiteSpace(message.FromFull.Email) && !String.IsNullOrWhiteSpace(message.FromFull.Name)) { dlqi.Message.FromEmail = message.FromFull.Email.Trim(); dlqi.Message.FromName = message.FromFull.Name.Trim(); } dlqi.Message.Subject = message.Subject; dlqi.Message.HtmlBody = message.HtmlBody; dlqi.Message.TextBody = message.TextBody; dlqi.Message.MessageID = message.MessageID; _queueService.EnqueueDistributionListBroadcast(dlqi); } catch (Exception ex) { Logging.LogException(ex); return(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } else { return(new HttpResponseMessage(HttpStatusCode.Created)); } } return(new HttpResponseMessage(HttpStatusCode.Created)); #endregion Distribution Email } if (type == 3) // Group Dispatch { #region Group Dispatch Email var departmentGroup = _departmentGroupsService.GetGroupByDispatchEmailCode(emailAddress); if (departmentGroup != null) { try { var emailSettings = _departmentsService.GetDepartmentEmailSettings(departmentGroup.DepartmentId); //var departmentGroupUsers = _departmentGroupsService.GetAllMembersForGroup(departmentGroup.DepartmentGroupId); var departmentGroupUsers = _departmentGroupsService.GetAllMembersForGroupAndChildGroups(departmentGroup); var callEmail = new CallEmail(); callEmail.Subject = message.Subject; if (!String.IsNullOrWhiteSpace(message.HtmlBody)) { callEmail.Body = HttpUtility.HtmlDecode(message.HtmlBody); } else { callEmail.Body = message.TextBody; } foreach (var attachment in message.Attachments) { try { if (Convert.ToInt32(attachment.ContentLength) > 0) { if (attachment.Name.Contains(".mp3") || attachment.Name.Contains(".amr")) { byte[] filebytes = Convert.FromBase64String(attachment.Content); callEmail.DispatchAudioFileName = attachment.Name; callEmail.DispatchAudio = filebytes; } } } catch { } } if (emailSettings == null) { emailSettings = new DepartmentCallEmail(); emailSettings.FormatType = (int)CallEmailTypes.Generic; emailSettings.DepartmentId = departmentGroup.DepartmentId; if (departmentGroup.Department != null) { emailSettings.Department = departmentGroup.Department; } else { emailSettings.Department = _departmentsService.GetDepartmentById(departmentGroup.DepartmentId); } } var activeCalls = _callsService.GetActiveCallsByDepartment(emailSettings.Department.DepartmentId); var units = _unitsService.GetAllUnitsForGroup(departmentGroup.DepartmentGroupId); var priorities = _callsService.GetActiveCallPrioritesForDepartment(emailSettings.Department.DepartmentId); int defaultPriority = (int)CallPriority.High; if (priorities != null && priorities.Any()) { var defaultPrio = priorities.FirstOrDefault(x => x.IsDefault && x.IsDeleted == false); if (defaultPrio != null) { defaultPriority = defaultPrio.DepartmentCallPriorityId; } } var call = _callsService.GenerateCallFromEmail(emailSettings.FormatType, callEmail, emailSettings.Department.ManagingUserId, departmentGroupUsers.Select(x => x.User).ToList(), emailSettings.Department, activeCalls, units, defaultPriority); if (call != null) { call.DepartmentId = departmentGroup.DepartmentId; var savedCall = _callsService.SaveCall(call); var cqi = new CallQueueItem(); cqi.Call = savedCall; cqi.Profiles = _userProfileService.GetSelectedUserProfiles(departmentGroupUsers.Select(x => x.UserId).ToList()); cqi.DepartmentTextNumber = _departmentSettingsService.GetTextToCallNumberForDepartment(cqi.Call.DepartmentId); _queueService.EnqueueCallBroadcast(cqi); return(new HttpResponseMessage(HttpStatusCode.Created)); } } catch (Exception ex) { Logging.LogException(ex); return(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } #endregion Group Dispatch Email } if (type == 4) // Group Message { #region Group Message var departmentGroup = _departmentGroupsService.GetGroupByMessageEmailCode(emailAddress); if (departmentGroup != null) { try { //var departmentGroupUsers = _departmentGroupsService.GetAllMembersForGroup(departmentGroup.DepartmentGroupId); var departmentGroupUsers = _departmentGroupsService.GetAllMembersForGroupAndChildGroups(departmentGroup); var newMessage = new Message(); newMessage.SentOn = DateTime.UtcNow; newMessage.SendingUserId = departmentGroup.Department.ManagingUserId; newMessage.IsBroadcast = true; newMessage.Subject = message.Subject; newMessage.SystemGenerated = true; if (!String.IsNullOrWhiteSpace(message.HtmlBody)) { newMessage.Body = HttpUtility.HtmlDecode(message.HtmlBody); } else { newMessage.Body = message.TextBody; } foreach (var member in departmentGroupUsers) { if (newMessage.GetRecipients().All(x => x != member.UserId)) { newMessage.AddRecipient(member.UserId); } } var savedMessage = _messageService.SaveMessage(newMessage); _messageService.SendMessage(savedMessage, "", departmentGroup.DepartmentId, false); return(new HttpResponseMessage(HttpStatusCode.Created)); } catch (Exception ex) { Logging.LogException(ex); return(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } #endregion Group Message } return(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } catch (Exception ex) { Framework.Logging.LogException(ex); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(ex.ToString()) }); } } else { // If our message was null, we throw an exception throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("Error parsing Inbound Message, message is null.") }); } }