-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_emails.php
More file actions
executable file
·192 lines (166 loc) · 6.69 KB
/
load_emails.php
File metadata and controls
executable file
·192 lines (166 loc) · 6.69 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/**
* $Header: /cvsroot/bitweaver/_bit_contact/edit.php,v 1.6 2010/02/08 21:27:22 wjames5 Exp $
*
* Copyright (c) 2006 bitweaver.org
* All Rights Reserved. See below for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
*
* @package contact
* @subpackage functions
*/
/**
* required setup
*/
require_once '../kernel/includes/setup_inc.php';
use Bitweaver\Liberty\LibertyComment;
global $commentsLib, $gBitSmarty, $gBitSystem;
$gBitSystem->verifyPackage( 'contact' );
$gBitSystem->verifyPermission( 'p_contact_update' );
include_once CONTACT_PKG_INCLUDE_PATH . 'lookup_contact_inc.php';
if (!$gContent->mContentId) {
header( "location: " . CONTACT_PKG_URL . "list.php" );
die;
}
require_once 'import/Mbox.php';
require_once 'import/mimeDecode.php';
//reads a mbox file
$file = '/srv/website/bitweaver/contact/data/Shipped';
//echo 'Using file ' . $file . "<br>";
$mbox = new Mail_Mbox( $file );
$mbox->open();
for ( $n = 0; $n < $mbox->size(); $n++ ) {
$message = $mbox->get( $n );
preg_match( '/Subject: (.*)$/m', $message, $matches );
$subject = isset( $matches[1] ) ? $matches[1] : 'Not Set';$subject = 'Not Set';
// echo 'Mail #' . $n . ': ' . $subject . "<br>";
$Decoder = new Mail_mimeDecode( $message );
$params = array(
'include_bodies' => true,
'decode_bodies' => true,
'decode_headers' => true,
);
$Decoded = $Decoder->decode( $params );
if (strtolower( $Decoded->ctype_primary ) == "multipart") {
// \Bitweaver\vd($Decoded->parts[0]->ctype_primary);
$ctype_secondary = $Decoded->parts[0]->ctype_secondary;
if (strtolower( $Decoded->parts[0]->ctype_primary ) == "multipart") {
if (!empty( $Decoded->parts[0]->parts[0]->body )) {
$body = $Decoded->parts[0]->parts[0]->body;
} else {
\Bitweaver\vd( $Decoded );
}
} else {
$body = $Decoded->parts[0]->body;
}
}
else if (strtolower( $Decoded->ctype_primary ) == "text") {
// \Bitweaver\vd($Decoded->ctype_primary);
$ctype_secondary = $Decoded->ctype_secondary;
if (!empty( $Decoded->body )) {
$body = $Decoded->body;
} else {
\Bitweaver\vd( $Decoded );
}
} else {
\Bitweaver\vd( $message );
\Bitweaver\vd( $Decoded );
break;
}
$em_date = str_replace( '(GMT Daylight Time)', 'BST', $Decoded->headers['date'] );
$em_date = str_replace( '(West-Europa (standaardtijd))', '', $em_date );
$dateTime = new DateTime( $em_date );
$email = [];
$email['comments_parent_id'] = $gContent->mContentId;
$email['comment_title'] = $subject;
$email['comment_data'] = $body;
$email['created'] = strtotime( $dateTime->format(DATE_ATOM) );
$email['last_modified'] = strtotime( $dateTime->format(DATE_ATOM) );
$email['summary'] = $message;
$email['format_guid'] = ( $ctype_secondary == 'html' ) ? 'bithtml' : 'simpletext';
$storeComment = new LibertyComment();
/*
* Process email addresses from the file
// define our search pattern to extract any email addresses
// $pattern = '#(?<=s/)[^\s@]+@[^\s@_]#';
// $pattern = '/([A-Za-z0-9\.\-\_\!\#\$\%\&\'\*\+\/\=\?\^\`\{\|\}]+)\@([A-Za-z0-9.-_]+)(\.[A-Za-z]{2,5})/';
$pattern = '/([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i';
// preg match all in the string
preg_match_all( $pattern, $Decoded->headers['from'], $emails );
if ( !empty($emails[0]) ) {
if ( $emails[0][0] == 'lester@lsces.co.uk' ) {
preg_match_all( $pattern, $Decoded->headers['to'], $to_emails );
}
if ( !empty($to_emails[0]) ) {
$from_emails = array_unique($to_emails[0]);
} else {
$from_emails = array_unique($emails[0]);
}
$sql = "SELECT e.* FROM `".BIT_DB_PREFIX."contact_email` e WHERE e.`email` = ?";
$result = $storeComment->mDb->getRow( $sql, $from_emails );
if( $result ) {
$table = BIT_DB_PREFIX."contact_email";
$email['email_store']['end_date'] = strtotime( $dateTime->format(DATE_ATOM) );
$result = $storeComment->mDb->associateUpdate( $table, $email['email_store'], array( "email" => $from_emails[0] ) );
} else {
$table = BIT_DB_PREFIX."contact_email";
$email['email_store']['email'] = $from_emails[0];
$email['email_store']['start_date'] = strtotime( $dateTime->format(DATE_ATOM) );
$email['email_store']['end_date'] = strtotime( $dateTime->format(DATE_ATOM) );
$result = $storeComment->mDb->associateInsert( $table, $email['email_store'] );
}
} else {
\Bitweaver\vd( $Decoded->headers );
}
*/
// define our search pattern to extract any email addresses
// $pattern = '#(?<=s/)[^\s@]+@[^\s@_]#';
// $pattern = '/([A-Za-z0-9\.\-\_\!\#\$\%\&\'\*\+\/\=\?\^\`\{\|\}]+)\@([A-Za-z0-9.-_]+)(\.[A-Za-z]{2,5})/';
$pattern = '/([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i';
// preg match all in the string
preg_match_all( $pattern, $Decoded->headers['from'], $emails );
if ( !empty($emails[0]) ) {
if ( $emails[0][0] == 'lester@lsces.co.uk' ) {
preg_match_all( $pattern, $Decoded->headers['to'], $to_emails );
}
$from_emails = ( !empty( $to_emails[0] ) ) ? array_unique( $to_emails[0] ) : array_unique( $emails[0] );
$sql = "SELECT e.content_id FROM `" . BIT_DB_PREFIX . "contact_xref` e WHERE e.`xkey_ext` = ?";
$result = $storeComment->mDb->getRow( $sql, $from_emails );
if ($result) {
$email['comments_parent_id'] = $result['content_id'];
} else {
$sql = "SELECT e.* FROM `" . BIT_DB_PREFIX . "contact_email` e WHERE e.`email` = ?";
$result = $storeComment->mDb->getRow( $sql, $from_emails );
if ($result) {
$table = BIT_DB_PREFIX . "contact_email";
$email['email_store']['end_date'] = strtotime( $dateTime->format( DATE_ATOM ) );
$result = $storeComment->mDb->associateUpdate( $table, $email['email_store'], array( "email" => $from_emails[0] ) );
} else {
$table = BIT_DB_PREFIX . "contact_email";
$email['email_store']['email'] = $from_emails[0];
$email['email_store']['start_date'] = strtotime( $dateTime->format( DATE_ATOM ) );
$email['email_store']['end_date'] = strtotime( $dateTime->format( DATE_ATOM ) );
$result = $storeComment->mDb->associateInsert( $table, $email['email_store'] );
}
}
} else {
\Bitweaver\vd( $Decoded->headers );
}
/*
if( $storeComment->storeComment( &$email )) {
// store successful
}
*/
}
$mbox->close();
if ($gContent->isCommentable()) {
$commentsParentId = $gContent->mContentId;
$comments_vars = array( 'contact' );
$comments_prefix_var = 'contact:';
$comments_object_var = 'contact';
$comments_return_url = $_SERVER['PHP_SELF'] . "?content_id=" . $gContent->mContentId;
include_once LIBERTY_PKG_PATH . 'comments_inc.php';
}
$gContent->mInfo['type'] = $gContent->getContactGroupList();
$gBitSystem->setBrowserTitle("Contact Information");
$gBitSystem->display( 'bitpackage:contact/show_contact.tpl');