-
Notifications
You must be signed in to change notification settings - Fork 2
/
webfetch.php
70 lines (56 loc) · 1.78 KB
/
webfetch.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
header('content-type: text/plain; charset=utf-8');
require("ii-functions.php");
function getfile($add) {
echo "fetch ".$add."\n";
return file_get_contents($add);
}
function parseFullEchoList($echobundle) {
$echos2d=array();
$lastecho="";
for($i=0;$i<count($echobundle);$i++) {
if(!empty($echobundle[$i])) {
$search=strpos($echobundle[$i], ".");
if($search===false) {
$echos2d[$lastecho][]=$echobundle[$i];
} else {
$lastecho=$echobundle[$i];
$echos2d[$lastecho]=array();
}
}
}
return $echos2d;
}
function fetch_messages($config, $one_request_limit=20, $fetch_limit=false, $xcenable=false) {
// xcenable - not implemented, fetch_limit - only N messages at time
global $access;
$echoesToFetch=array_slice($config,1);
$adress=$config[0];
$bundleAdress=$adress."u/e/".implode("/", $echoesToFetch);
$bundleAdress.=($fetch_limit) ? "/-".$fetch_limit.":".$fetch_limit : "";
$echoBundle=explode("\n", getfile($bundleAdress));
$remoteEchos2d=parseFullEchoList($access->applyBlackList($echoBundle));
foreach($echoesToFetch as $echo) {
$localMessages=$access->getMsgList($echo);
$remoteMessages=$remoteEchos2d[$echo];
$difference=array_diff($remoteMessages, $localMessages);
$difference2d=array_chunk($difference, $one_request_limit);
foreach ($difference2d as $diff) {
echo $echo."\n";
$impldifference=implode("/",$diff);
$fullbundle=getfile($adress."u/m/$impldifference");
$bundles=explode("\n",$fullbundle);
foreach($bundles as $bundle) {
$arr=explode(":",$bundle);
if(!empty($arr[0])) {
$msgid=$arr[0]; $message=b64d($arr[1]);
$hash=$access->saveMessage($msgid, $echo, $message, $raw=true);
if ($hash) {
echo "message saved: ok\n";
} else echo "error saving ".$msgid."\n";
}
}
}
}
}
?>