0

Estoy intentando leer desde el framework "Laravel 5.5" y/o directamente PHP (incluso me valdría algo que pasara a MySQL o un gestor de base de datos para después tratarlo) unas copias de seguridad de 1TB en total, repartidas en archivos de 100GB, 200GB (es importante el tamaño) guardadas en formato .EDB (Microsoft Exange) y .PST (Outlook).

El problema viene al no poder ser capaz de leer los archivos, y las pocas soluciones que encontré no son viables para estos tamaños de archivos:

  • Parsear todo a CSV e importarlo a MySQL
  • Restaurarlo en Gmail, luego parsealas a IMAP y posteriormente leerla con una librería de PHP.
  • Activar la función EXEC de PHP y probar usando codigo en C#/Batch (esta no me llego a funcionar)

Código .bat

$olApp = New-Object -com Outlook.Application
$namespace = $olApp.GetNamespace("MAPI")
$folder = $namespace.GetDefaultFolder(1)
$folder.Items  | %{ 
    "insert into MyTable (MyCol1, MyCol2, etc) values ($_.Subject, $_.body, etc)"
} | out-file "outfile.sql" -Append

Código C#

// Dumps all email in Outlook to console window.
// Prompts user with warning that an application is attempting to read Outlook data.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace OutlookEmail
{
class Program
{
    static void Main(string[] args)
    {
        Outlook.Application app = new Outlook.Application();
        Outlook.NameSpace outlookNs = app.GetNamespace("MAPI");
        Outlook.MAPIFolder emailFolder = outlookNs.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

        foreach (Outlook.MailItem item in emailFolder.Items)
        {
            Console.WriteLine(item.SenderEmailAddress + " " + item.Subject + "\n" + item.Body);
        }
        Console.ReadKey();
    }
}
}

Fuentes de soluciones:

RESUMEN: ¿Alguna idea para pasar offline EDB/PST con archivos a MySQL?

1 respuesta 1

0

Por si a alguien le vale, me cree un macro en Vbscript para outlook para resolver esto.

    Option Explicit

'***********************************************************************
'* Code based on sample code from Martin Green and adapted to my needs
'***********************************************************************

Sub GetAttachments()
On Error Resume Next
'create the folder if it doesnt exists:
    Dim fso, ttxtfile, txtfile, WheretosaveFolder
    Dim objFolders As Object
    Set objFolders = CreateObject("WScript.Shell").SpecialFolders

    ' MySQL Conexion
    Dim cn As Object
    Dim sCon As String
    Dim sSQL As String

    Set cn = CreateObject("ADODB.Connection")
    sCon = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=correos;User=root;Option=3;"
    cn.Open sCon

    'MsgBox objFolders("mydocuments")
    ttxtfile = objFolders("mydocuments")

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set txtfile = fso.CreateFolder(ttxtfile & "\Email Attachments")
    ' Changes made by Mrobles (mrobles@cedesa.es) on October 27th 2017
    ' ------------------------------------------------------
    ' Set fso = Nothing
    ' ------------------------------------------------------
     WheretosaveFolder = ttxtfile & "\Email Attachments"


On Error GoTo GetAttachments_err
' Declare variables
    Dim ns As NameSpace
    Dim Inbox As MAPIFolder
    Dim Item As Object
    Dim Atmt As Attachment
    Dim FileName As String
    Dim i As Integer
    Set ns = GetNamespace("MAPI")
    'Set Inbox = ns.GetDefaultFolder(olFolderInbox)
    ' added the option to select whic folder to export
    Set Inbox = ns.PickFolder

    'to handle if the use cancalled folder selection
    If Inbox Is Nothing Then
                MsgBox "You need to select a folder in order to save the attachments", vbCritical, _
               "Export - Not Found"
        Exit Sub
    End If

    ''''


    i = 0
' Check Inbox for messages and exit of none found
    If Inbox.Items.Count = 0 Then
        MsgBox "There are no messages in the selected folder.", vbInformation, _
               "Export - Not Found"
        Exit Sub
    End If
' Check each message for attachments

    cn.BeginTrans

    For Each Item In Inbox.Items

    sSQL = "INSERT INTO emails (" & _
     "ConversationID," & _
     "ConversationIndex," & _
     "SenderEmailAddress," & _
     "SendUsingAccount_SmtpAddress," & _
     "Subject," & _
     "ReceivedTime," & _
     "LastModificationTime," & _
     "EntryID," & _
     "HTMLBody," & _
     "Body" & _
    ") VALUES (" & _
    "'" & Item.ConversationID & "'," & _
    "'" & Item.ConversationIndex & "'," & _
    "'" & Item.SenderEmailAddress & "'," & _
    "'" & Item.SendUsingAccount.SmtpAddress & "'," & _
    "'" & Item.Subject & "'," & _
    "'" & Item.ReceivedTime & "'," & _
    "'" & Item.LastModificationTime & "'," & _
    "'" & Item.EntryID & "'," & _
    "'" & Item.HTMLBody & "'," & _
    "'" & Item.Body & "'" & _
    ")"
    cn.Execute sSQL


    ' End XLS'

' Save any attachments found
        For Each Atmt In Item.Attachments
        ' This path must exist! Change folder name as necessary.

        ' Changes made by Mrobles (mrobles@cedesa.es) on October 27th 2017
        ' ------------------------------------------------------
            FileName = WheretosaveFolder & "\" & Item.ConversationID & "_" & fso.GetBaseName(Atmt.FileName) & i & "." & fso.GetExtensionName(Atmt.FileName)
        ' ------------------------------------------------------
            Atmt.SaveAsFile FileName

            i = i + 1

         Next Atmt
    Next Item

    cn.CommitTrans

' Show summary message
    If i > 0 Then
        MsgBox "There were " & i & " attached files." _
        & vbCrLf & "These have been saved to the Email Attachments folder in My Documents." _
        '& vbCrLf & vbCrLf & "Thank you for using Liron Segev - TheTechieGuy's utility", vbInformation, "Export Complete"'
    Else
        MsgBox "There were no attachments found in any mails.", vbInformation, "Export - Not Found"
    End If
    ' Changes made by Mrobles (mrobles@cedesa.es) on October 27th 2017
    ' ------------------------------------------------------
        Set fso = Nothing
    ' ------------------------------------------------------
' Clear memory
GetAttachments_exit:
    Set Atmt = Nothing
    Set Item = Nothing
    Set ns = Nothing
    Exit Sub
' Handle errors
GetAttachments_err:
    MsgBox "An unexpected error has occurred." _
        & vbCrLf & "Please note and report the following information." _
        & vbCrLf & "Macro Name: GetAttachments" _
        & vbCrLf & "Error Number: " & Err.Number _
        & vbCrLf & "Error Description: " & Err.Description _
        , vbCritical, "Error!"
    Resume GetAttachments_exit
End Sub

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.