MCPcopy Create free account
hub / github.com/M66B/FairEmail / filter

Method filter

app/src/main/java/eu/faircode/email/Adguard.java:75–340  ·  view source on GitHub ↗
(Context context, Uri uri)

Source from the content-addressed store, hash-verified

73 ));
74
75 @Nullable
76 public static Uri filter(Context context, Uri uri) {
77 if (uri.isOpaque())
78 return null;
79
80 String host = uri.getHost();
81 if (TextUtils.isEmpty(host))
82 return null;
83
84 File file = getFile(context);
85 if (!file.exists())
86 return null;
87
88 List<String> removes = new ArrayList<>();
89 List<String> importants = new ArrayList<>();
90 List<String> excepts = new ArrayList<>();
91
92 try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)))) {
93 String line;
94 while ((line = br.readLine()) != null) {
95 // https://adguard.com/kb/general/ad-filtering/create-own-filters/#comments
96 if (TextUtils.isEmpty(line) || line.startsWith("!"))
97 continue;
98
99 // rule = ["@@"] pattern [ "$" modifiers ]
100 // modifiers = [modifier0, modifier1[, ...[, modifierN]]]
101
102 int dollar = line.indexOf('$');
103 while (dollar > 0 && line.charAt(dollar - 1) == '\\')
104 dollar = line.indexOf('$', dollar + 1);
105 if (dollar < 0) {
106 // ||https-filtering-check.adtidy.org^
107 if (!line.contains("##"))
108 Log.w("Adguard command missing line=" + line);
109 continue;
110 }
111
112 String pattern = line.substring(0, dollar)
113 .replace("\\$", "$");
114 String rest = line.substring(dollar + 1)
115 .replace("\\$", "$");
116
117 int start = 0;
118 List<String> modifiers = new ArrayList<>();
119 while (start < rest.length()) {
120 int comma = rest.indexOf(',', start);
121 while (comma > 0 && rest.charAt(comma - 1) == '\\')
122 comma = rest.indexOf(',', comma + 1);
123 int end = (comma < 0 ? rest.length() : comma);
124 modifiers.add(rest.substring(start, end)
125 .replace("\\,", ","));
126 start = (comma < 0 ? end : end + 1);
127 }
128
129 String remove = null;
130 boolean important = false;
131 boolean matches = true;
132 List<String> contents = new ArrayList<>();

Callers 11

sanitizeMethod · 0.95
rFunction · 0.45
performVerificationMethod · 0.45
verifySignedRecordsMethod · 0.45
sanitizeMethod · 0.45
isStyledMethod · 0.45
removeSignaturesMethod · 0.45
truncateMethod · 0.45
onActivityCreatedMethod · 0.45
onMenuJunkMethod · 0.45
onAccountFilterMethod · 0.45

Calls 15

getFileMethod · 0.95
wMethod · 0.95
iMethod · 0.95
guessMimeTypeMethod · 0.95
eMethod · 0.95
omitParamMethod · 0.95
indexOfMethod · 0.80
charAtMethod · 0.80
addAllMethod · 0.80
joinMethod · 0.80
sizeMethod · 0.65
getHostMethod · 0.45

Tested by

no test coverage detected