Skip to content

Commit

Permalink
If obfuscation in other direction, return unaltered target string.
Browse files Browse the repository at this point in the history
  • Loading branch information
phw198 committed Mar 14, 2022
1 parent 9aecda4 commit 8b45d9a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/OutlookGoogleCalendarSync/GoogleOgcs/GoogleCalendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private Event createCalendarEntry(AppointmentItem ai) {
}
ev = OutlookOgcs.Calendar.Instance.IOutlook.IANAtimezone_set(ev, ai);

ev.Summary = Obfuscate.ApplyRegex(ai.Subject, Sync.Direction.OutlookToGoogle);
ev.Summary = Obfuscate.ApplyRegex(ai.Subject, null, Sync.Direction.OutlookToGoogle);
if (profile.AddDescription) {
try {
ev.Description = ai.Body;
Expand Down Expand Up @@ -735,7 +735,7 @@ public Event UpdateCalendarEntry(AppointmentItem ai, Event ev, ref int itemModif
Sync.Engine.CompareAttribute("End Timezone", Sync.Direction.OutlookToGoogle, currentEndTZ, ev.End.TimeZone, sb, ref itemModified);
}

String subjectObfuscated = Obfuscate.ApplyRegex(ai.Subject, Sync.Direction.OutlookToGoogle);
String subjectObfuscated = Obfuscate.ApplyRegex(ai.Subject, ev.Summary, Sync.Direction.OutlookToGoogle);
if (Sync.Engine.CompareAttribute("Subject", Sync.Direction.OutlookToGoogle, ev.Summary, subjectObfuscated, sb, ref itemModified)) {
ev.Summary = subjectObfuscated;
}
Expand Down Expand Up @@ -1672,9 +1672,9 @@ public static Boolean SignaturesMatch(String sigEv, String sigAi) {

if (profile.Obfuscation.Enabled) {
if (profile.Obfuscation.Direction.Id == Sync.Direction.OutlookToGoogle.Id)
sigAi = Obfuscate.ApplyRegex(sigAi, Sync.Direction.OutlookToGoogle);
sigAi = Obfuscate.ApplyRegex(sigAi, null, Sync.Direction.OutlookToGoogle);
else
sigEv = Obfuscate.ApplyRegex(sigEv, Sync.Direction.GoogleToOutlook);
sigEv = Obfuscate.ApplyRegex(sigEv, null, Sync.Direction.GoogleToOutlook);
}
return (sigEv == sigAi);
}
Expand Down
35 changes: 23 additions & 12 deletions src/OutlookGoogleCalendarSync/Obfuscate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,33 @@ public void LoadRegex(DataGridView data) {
data.CurrentCell = data.Rows[0].Cells[0];
}

public static String ApplyRegex(String source, Sync.Direction direction) {
/// <summary>
/// Apply regular expression to a source string, if syncing in the correct direction
/// </summary>
/// <param name="source">Source calendar string</param>
/// <param name="target">Target calendar string, null if creating</param>
/// <param name="direction">Direction engine is being synced</param>
/// <returns></returns>
public static String ApplyRegex(String source, String target, Sync.Direction direction) {
String retStr = source ?? "";
if (Sync.Engine.Calendar.Instance.Profile.Obfuscation.Enabled && direction.Id == Sync.Engine.Calendar.Instance.Profile.Obfuscation.Direction.Id) {
foreach (DataGridViewRow row in Forms.Main.Instance.dgObfuscateRegex.Rows) {
DataGridViewCellCollection cells = row.Cells;
if (cells[Obfuscate.findCol].Value != null) {
System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex(
cells[Obfuscate.findCol].Value.ToString(), System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (Sync.Engine.Calendar.Instance.Profile.Obfuscation.Enabled) {
if (direction.Id == Sync.Engine.Calendar.Instance.Profile.Obfuscation.Direction.Id) {
foreach (DataGridViewRow row in Forms.Main.Instance.dgObfuscateRegex.Rows) {
DataGridViewCellCollection cells = row.Cells;
if (cells[Obfuscate.findCol].Value != null) {
System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex(
cells[Obfuscate.findCol].Value.ToString(), System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.MatchCollection matches = rgx.Matches(retStr);
if (matches.Count > 0) {
log.Fine("Regex has matched and altered string: " + cells[Obfuscate.findCol].Value.ToString());
if (cells[Obfuscate.replaceCol].Value == null) cells[Obfuscate.replaceCol].Value = "";
retStr = rgx.Replace(retStr, cells[Obfuscate.replaceCol].Value.ToString());
System.Text.RegularExpressions.MatchCollection matches = rgx.Matches(retStr);
if (matches.Count > 0) {
log.Fine("Regex has matched and altered string: " + cells[Obfuscate.findCol].Value.ToString());
if (cells[Obfuscate.replaceCol].Value == null) cells[Obfuscate.replaceCol].Value = "";
retStr = rgx.Replace(retStr, cells[Obfuscate.replaceCol].Value.ToString());
}
}
}
} else {
retStr = target ?? source;
}
}
return retStr;
Expand Down
4 changes: 2 additions & 2 deletions src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private void createCalendarEntry(Event ev, ref AppointmentItem ai) {
ai = OutlookOgcs.Calendar.Instance.IOutlook.WindowsTimeZone_set(ai, ev);
Recurrence.Instance.BuildOutlookPattern(ev, ai);

ai.Subject = Obfuscate.ApplyRegex(ev.Summary, Sync.Direction.GoogleToOutlook);
ai.Subject = Obfuscate.ApplyRegex(ev.Summary, null, Sync.Direction.GoogleToOutlook);
if (profile.AddDescription && ev.Description != null) ai.Body = ev.Description;
if (profile.AddLocation) ai.Location = ev.Location;
ai.Sensitivity = getPrivacy(ev.Visibility, null);
Expand Down Expand Up @@ -513,7 +513,7 @@ public Boolean UpdateCalendarEntry(ref AppointmentItem ai, Event ev, ref int ite
}
#endregion

String summaryObfuscated = Obfuscate.ApplyRegex(ev.Summary, Sync.Direction.GoogleToOutlook);
String summaryObfuscated = Obfuscate.ApplyRegex(ev.Summary, ai.Subject, Sync.Direction.GoogleToOutlook);
if (Sync.Engine.CompareAttribute("Subject", Sync.Direction.GoogleToOutlook, summaryObfuscated, ai.Subject, sb, ref itemModified)) {
ai.Subject = summaryObfuscated;
}
Expand Down

0 comments on commit 8b45d9a

Please sign in to comment.