| 253 | | |
| 254 | | # Ham cache table |
| 255 | | $select = "SELECT maia_mail_recipients.token, maia_mail.received_date, maia_mail.score, " . |
| 256 | | "maia_mail.sender_email, maia_mail.subject " . |
| 257 | | "FROM maia_mail, maia_mail_recipients " . |
| 258 | | "WHERE maia_mail.id = maia_mail_recipients.mail_id " . |
| 259 | | "AND maia_mail_recipients.type = 'H' " . |
| 260 | | "AND maia_mail_recipients.recipient_id = ? " . |
| 261 | | "ORDER BY maia_mail.$ham_sort"; |
| 262 | | $sth = $dbh->prepare($select) |
| 263 | | or die (sprintf("Maia: [send-quarantine-digests] Couldn't prepare query: %s", $dbh->errstr)); |
| 264 | | $sth->execute($user_id) |
| 265 | | or die (sprintf("Maia: [send-quarantine-digests] Couldn't execute query: %s", $dbh->errstr)); |
| 266 | | if ($sth->rows > 0) { |
| 267 | | $at_least_one = 1; |
| 268 | | $rowcount = 0; |
| 269 | | while (@row = $sth->fetchrow_array()) { |
| 270 | | $token = $1 if $row[0] =~ /^([a-zA-Z0-9]{32})$/si; # untaint |
| 271 | | $received_date = $1 if $row[1] =~ /^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})$/si; # untaint |
| 272 | | $score = $1 if $row[2] =~ /^(\d+\.\d+)$/si; # untaint |
| 273 | | $sender = $1 if $row[3] =~ /^(.+\@.+\..+)$/si; # untaint |
| 274 | | $subject = $1 if $row[4] =~ /^(.*)$/si; # untaint |
| 275 | | if ($subject eq "") { |
| 276 | | $subject = "(no subject)"; |
| 277 | | } |
| 278 | | |
| 279 | | $vars{'list'}{'ham'}[$rowcount]{'token'} = $token; |
| 280 | | $vars{'list'}{'ham'}[$rowcount]{'received_date'} = $received_date; |
| 281 | | $vars{'list'}{'ham'}[$rowcount]{'score'} = $score; |
| 282 | | $vars{'list'}{'ham'}[$rowcount]{'sender'} = $sender; |
| 283 | | $vars{'list'}{'ham'}[$rowcount]{'subject'} = $subject; |
| 284 | | |
| 285 | | $rowcount++; |
| 286 | | } |
| 287 | | } |
| 288 | | $sth->finish(); |
| 289 | | |
| 290 | | # Spam Quarantine table |
| 291 | | $select = "SELECT maia_mail_recipients.token, maia_mail.received_date, maia_mail.score, " . |
| 292 | | "maia_mail.sender_email, maia_mail.subject " . |
| 293 | | "FROM maia_mail, maia_mail_recipients " . |
| 294 | | "WHERE maia_mail.id = maia_mail_recipients.mail_id " . |
| 295 | | "AND maia_mail_recipients.type = 'S' " . |
| 296 | | "AND maia_mail_recipients.recipient_id = ? " . |
| 297 | | "ORDER BY maia_mail.$spam_sort"; |
| 298 | | $sth = $dbh->prepare($select) |
| 299 | | or die (sprintf("Maia: [send-quarantine-digests] Couldn't prepare query: %s", $dbh->errstr)); |
| 300 | | $sth->execute($user_id) |
| 301 | | or die (sprintf("Maia: [send-quarantine-digests] Couldn't execute query: %s", $dbh->errstr)); |
| 302 | | if ($sth->rows > 0) { |
| 303 | | $at_least_one = 1; |
| 304 | | $rowcount = 0; |
| 305 | | while (@row = $sth->fetchrow_array()) { |
| 306 | | $token = $1 if $row[0] =~ /^([a-zA-Z0-9]{32})$/si; # untaint |
| 307 | | $received_date = $1 if $row[1] =~ /^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})$/si; # untaint |
| 308 | | $score = $1 if $row[2] =~ /^(\d+\.\d+)$/si; # untaint |
| 309 | | $sender = $1 if $row[3] =~ /^(.+\@.+\..+)$/si; # untaint |
| 310 | | $subject = $1 if $row[4] =~ /^(.*)$/si; # untaint |
| 311 | | if ($subject eq "") { |
| 312 | | $subject = "(no subject)"; |
| 313 | | } |
| 314 | | |
| 315 | | $vars{'list'}{'spam'}[$rowcount]{'token'} = $token; |
| 316 | | $vars{'list'}{'spam'}[$rowcount]{'received_date'} = $received_date; |
| 317 | | $vars{'list'}{'spam'}[$rowcount]{'score'} = $score; |
| 318 | | $vars{'list'}{'spam'}[$rowcount]{'sender'} = $sender; |
| 319 | | $vars{'list'}{'spam'}[$rowcount]{'subject'} = $subject; |
| 320 | | |
| 321 | | $rowcount++; |
| 322 | | } |
| 323 | | } |
| 324 | | $sth->finish(); |
| 325 | | |
| 326 | | # Virus Quarantine table |
| 327 | | $select = "SELECT maia_mail_recipients.token, maia_mail.received_date, " . |
| 328 | | "maia_mail.sender_email, maia_mail.subject " . |
| 329 | | "FROM maia_mail, maia_mail_recipients " . |
| 330 | | "WHERE maia_mail.id = maia_mail_recipients.mail_id " . |
| 331 | | "AND maia_mail_recipients.type = 'V' " . |
| 332 | | "AND maia_mail_recipients.recipient_id = ? " . |
| 333 | | "ORDER BY maia_mail.$virus_sort"; |
| 334 | | $sth = $dbh->prepare($select) |
| 335 | | or die (sprintf("Maia: [send-quarantine-digests] Couldn't prepare query: %s", $dbh->errstr)); |
| 336 | | $sth->execute($user_id) |
| 337 | | or die (sprintf("Maia: [send-quarantine-digests] Couldn't execute query: %s", $dbh->errstr)); |
| 338 | | if ($sth->rows > 0) { |
| 339 | | $at_least_one = 1; |
| 340 | | $rowcount = 0; |
| 341 | | while (@row = $sth->fetchrow_array()) { |
| 342 | | $token = $1 if $row[0] =~ /^([a-zA-Z0-9]{32})$/si; # untaint |
| 343 | | $received_date = $1 if $row[1] =~ /^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})$/si; # untaint |
| 344 | | $sender = $1 if $row[2] =~ /^(.+\@.+\..+)$/si; # untaint |
| 345 | | $subject = $1 if $row[3] =~ /^(.*)$/si; # untaint |
| 346 | | if ($subject eq "") { |
| 347 | | $subject = "(no subject)"; |
| 348 | | } |
| 349 | | |
| 350 | | $vars{'list'}{'virus'}[$rowcount]{'token'} = $token; |
| 351 | | $vars{'list'}{'virus'}[$rowcount]{'received_date'} = $received_date; |
| 352 | | $vars{'list'}{'virus'}[$rowcount]{'sender'} = $sender; |
| 353 | | $vars{'list'}{'virus'}[$rowcount]{'subject'} = $subject; |
| 354 | | $rowcount++; |
| 355 | | } |
| 356 | | } |
| 357 | | $sth->finish(); |
| 358 | | |
| 359 | | # Attachment Quarantine table |
| 360 | | $select = "SELECT maia_mail_recipients.token, maia_mail.received_date, " . |
| 361 | | "maia_mail.sender_email, maia_mail.subject " . |
| 362 | | "FROM maia_mail, maia_mail_recipients " . |
| 363 | | "WHERE maia_mail.id = maia_mail_recipients.mail_id " . |
| 364 | | "AND maia_mail_recipients.type = 'F' " . |
| 365 | | "AND maia_mail_recipients.recipient_id = ? " . |
| 366 | | "ORDER BY maia_mail.$banned_file_sort"; |
| 367 | | $sth = $dbh->prepare($select) |
| 368 | | or die (sprintf("Maia: [send-quarantine-digests] Couldn't prepare query: %s", $dbh->errstr)); |
| 369 | | $sth->execute($user_id) |
| 370 | | or die (sprintf("Maia: [send-quarantine-digests] Couldn't execute query: %s", $dbh->errstr)); |
| 371 | | if ($sth->rows > 0) { |
| 372 | | $at_least_one = 1; |
| 373 | | $rowcount = 0; |
| 374 | | while (@row = $sth->fetchrow_array()) { |
| 375 | | $token = $1 if $row[0] =~ /^([a-zA-Z0-9]{32})$/si; # untaint |
| 376 | | $received_date = $1 if $row[1] =~ /^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})$/si; # untaint |
| 377 | | $sender = $1 if $row[2] =~ /^(.+\@.+\..+)$/si; # untaint |
| 378 | | $subject = $1 if $row[3] =~ /^(.*)$/si; # untaint |
| 379 | | if ($subject eq "") { |
| 380 | | $subject = "(no subject)"; |
| 381 | | } |
| 382 | | |
| 383 | | $vars{'list'}{'banned_file'}[$rowcount]{'token'} = $token; |
| 384 | | $vars{'list'}{'banned_file'}[$rowcount]{'received_date'} = $received_date; |
| 385 | | $vars{'list'}{'banned_file'}[$rowcount]{'sender'} = $sender; |
| 386 | | $vars{'list'}{'banned_file'}[$rowcount]{'subject'} = $subject; |
| 387 | | |
| 388 | | $rowcount++; |
| 389 | | } |
| 390 | | } |
| 391 | | $sth->finish(); |
| 392 | | |
| 393 | | # Invalid Header Quarantine table |
| 394 | | $select = "SELECT maia_mail_recipients.token, maia_mail.received_date, " . |
| 395 | | "maia_mail.sender_email, maia_mail.subject " . |
| 396 | | "FROM maia_mail, maia_mail_recipients " . |
| 397 | | "WHERE maia_mail.id = maia_mail_recipients.mail_id " . |
| 398 | | "AND maia_mail_recipients.type = 'B' " . |
| 399 | | "AND maia_mail_recipients.recipient_id = ? " . |
| 400 | | "ORDER BY maia_mail.$bad_header_sort"; |
| 401 | | $sth = $dbh->prepare($select) |
| 402 | | or die (sprintf("Maia: [send-quarantine-digests] Couldn't prepare query: %s", $dbh->errstr)); |
| 403 | | $sth->execute($user_id) |
| 404 | | or die (sprintf("Maia: [send-quarantine-digests] Couldn't execute query: %s", $dbh->errstr)); |
| 405 | | if ($sth->rows > 0) { |
| 406 | | $at_least_one = 1; |
| 407 | | $rowcount = 0; |
| 408 | | while (@row = $sth->fetchrow_array()) { |
| 409 | | $token = $1 if $row[0] =~ /^([a-zA-Z0-9]{32})$/si; # untaint |
| 410 | | $received_date = $1 if $row[1] =~ /^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})$/si; # untaint |
| 411 | | $sender = $1 if $row[2] =~ /^(.+\@.+\..+)$/si; # untaint |
| 412 | | $subject = $1 if $row[3] =~ /^(.*)$/si; # untaint |
| 413 | | if ($subject eq "") { |
| 414 | | $subject = "(no subject)"; |
| 415 | | } |
| 416 | | |
| 417 | | $vars{'list'}{'bad_header'}[$rowcount]{'token'} = $token; |
| 418 | | $vars{'list'}{'bad_header'}[$rowcount]{'received_date'} = $received_date; |
| 419 | | $vars{'list'}{'bad_header'}[$rowcount]{'sender'} = $sender; |
| 420 | | $vars{'list'}{'bad_header'}[$rowcount]{'subject'} = $subject; |
| 421 | | $rowcount++; |
| 422 | | } |
| 423 | | } |
| 424 | | $sth->finish(); |
| 425 | | |
| | 279 | $sth = $dbh->prepare($select) |
| | 280 | or die (sprintf("Maia: [send-quarantine-digests] Couldn't prepare query: %s", $dbh->errstr)); |
| | 281 | $sth->execute($user_id) |
| | 282 | or die (sprintf("Maia: [send-quarantine-digests] Couldn't execute query: %s", $dbh->errstr)); |
| | 283 | if ($sth->rows > 0) { |
| | 284 | $at_least_one = 1; |
| | 285 | $rowcount = 0; |
| | 286 | while (@row = $sth->fetchrow_array()) { |
| | 287 | $token = $1 if $row[0] =~ /^([a-zA-Z0-9]{32})$/si; # untaint |
| | 288 | $received_date = $1 if $row[1] =~ /^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})$/si; # untaint |
| | 289 | $score = $1 if $row[2] =~ /^(\d+\.\d+)$/si; # untaint |
| | 290 | $sender = $1 if $row[3] =~ /^(.+\@.+\..+)$/si; # untaint |
| | 291 | $subject = $1 if $row[4] =~ /^(.*)$/si; # untaint |
| | 292 | if ($subject eq "") { |
| | 293 | $subject = "(no subject)"; |
| | 294 | } |
| | 295 | |
| | 296 | $vars{'list'}[$report_count]{$report_element}[$rowcount]{'token'} = $token; |
| | 297 | $vars{'list'}[$report_count]{$report_element}[$rowcount]{'received_date'} = $received_date; |
| | 298 | if ($report_element eq 'ham' || $report_element eq 'spam') { |
| | 299 | $vars{'list'}[$report_count]{$report_element}[$rowcount]{'score'} = $score; |
| | 300 | } |
| | 301 | $vars{'list'}[$report_count]{$report_element}[$rowcount]{'sender'} = $sender; |
| | 302 | $vars{'list'}[$report_count]{$report_element}[$rowcount]{'subject'} = $subject; |
| | 303 | |
| | 304 | $rowcount++; |
| | 305 | } |
| | 306 | } |
| | 307 | $sth->finish(); |
| | 308 | $report_count++ |
| | 309 | } |
| | 310 | |