Search The ForumSearch   RegisterRegister  LoginLogin

AfterLogic WebMail Lite

 AfterLogic Forum : AfterLogic WebMail Lite
Subject Topic: Save attachements Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
pcwebservice
Newbie
Newbie
Avatar

Joined: 03 July 2021
Location: France
Online Status: Offline
Posts: 8
Posted: 05 July 2021 at 1:32am | IP Logged Quote pcwebservice

Hello,

I am using the PHP API and would like to save the attachments to the server, but I am unable to do so.
I have tried with getRaw, but I get an APIException error message. Could you help me please.
Back to Top View pcwebservice's Profile Search for other posts by pcwebservice
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6010
Posted: 05 July 2021 at 1:35am | IP Logged Quote Igor

Do you mean that you need to send mail out with attachments? Or this is about retrieving email message and attachments from it?

--
Regards,
Igor, Afterlogic Support

Back to Top View Igor's Profile Search for other posts by Igor
 
pcwebservice
Newbie
Newbie
Avatar

Joined: 03 July 2021
Location: France
Online Status: Offline
Posts: 8
Posted: 05 July 2021 at 1:43am | IP Logged Quote pcwebservice

retrieving email message and attachments from it.
sorry for my english with google translate .

I cannot use your excellent webmail because I need to add functionality to my web application for a client.

The recovery of mails, the list of folder, the visualization of an email works. I just have the problem of attachments that I cannot save locally on my server to be able to download them.

If you need to see my code to understand, I can provide it to you.

If I use the download or view link I get the following error message:
Code:
Fatal error: Uncaught TypeError: Argument 1 passed to Aurora\Modules\Mail\Managers\Main\Manager::_getImapClient() must be an instance of Aurora\Modules\Mail\Classes\Account, null given, called in /home/praufkea/preprod.ocourtier.fr/webmails/modules/Mail/Managers/Main/Manager.php on line 2263 and defined in /home/praufkea/preprod.ocourtier.fr/webmails/modules/Mail/Managers/Main/Manager.php:62 Stack trace: #0 /home/praufkea/preprod.ocourtier.fr/webmails/modules/Mail/Managers/Main/Manager.php(2263): Aurora\Modules\Mail\Managers\Main\Manager->_getImapClient(NULL) #1 /home/praufkea/preprod.ocourtier.fr/webmails/modules/Mail/Module.php(6884): Aurora\Modules\Mail\Managers\Main\Manager->directMessageToStream(NULL, Object(Closure), 'INBOX', 833, '1.2') #2 /home/praufkea/preprod.ocourtier.fr/webmails/modules/Mail/Module.php(6760): Aurora\Modules\Mail\Module->getRaw('pG2EMtRD9zrXsjh...', 'view') #3 [internal function]: Aurora\Modules\Mail\Module->EntryDownloadAttachment() #4 /home/praufkea/preprod.ocourtier.fr/webmails/system/Router in /home/praufkea/preprod.ocourtier.fr/webmails/modules/Mail/Managers/Main/Manager.php on line 62
Back to Top View pcwebservice's Profile Search for other posts by pcwebservice
 
pcwebservice
Newbie
Newbie
Avatar

Joined: 03 July 2021
Location: France
Online Status: Offline
Posts: 8
Posted: 05 July 2021 at 3:16am | IP Logged Quote pcwebservice

Can't you help me?
Back to Top View pcwebservice's Profile Search for other posts by pcwebservice
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6010
Posted: 05 July 2021 at 4:29am | IP Logged Quote Igor

Sorry, still not too sure what exactly you're doing, can you post the relevant code, just a few lines so I could get the idea?

--
Regards,
Igor, Afterlogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
pcwebservice
Newbie
Newbie
Avatar

Joined: 03 July 2021
Location: France
Online Status: Offline
Posts: 8
Posted: 05 July 2021 at 7:25am | IP Logged Quote pcwebservice

below the code to display the content of an email. I need to save the attachments in the $path folder, where the comment is.
I'll just need the base64 code from each attachment.
Code:

Api::Init(true);
$oCoreDecorator = Module::Decorator();
$oMailDecorator = \Aurora\Modules\Mail\Module::Decorator();
$sEmail     = $userConnected->getEmail();
$oUser      = $oCoreDecorator->GetUserByPublicId($sEmail);
$iUserId    = $oUser->EntityId;
$oAccount   = $oCoreDecorator->GetAccountUsedToAuthorize($sEmail);
$AccountID  = $oAccount->EntityId;
$oMessage   = $oMailDecorator->GetMessage($AccountID, $Folder, $Uid);
$aMessage   = $oMessage->toResponseArray(array('Method'=>'GetMessage'));
$subject    = isset($aMessage["Subject"]) && $aMessage["Subject"] !== '' ? $aMessage["Subject"] : 'Objet';
$fromMail   = isset($aMessage["From"]["@Collection"][0]["Email"]) && $aMessage["From"]["@Collection"][0]["Email"] !== '' ? $aMessage["From"]["@Collection"][0]["Email"] : '';
$fromName   = isset($aMessage["From"]["@Collection"][0]["DisplayName"]) && $aMessage["From"]["@Collection"][0]["DisplayName"] !== '' ? $aMessage["From"]["@Collection"][0]["DisplayName"] : '';
$date       = '';
if(isset($aMessage["ReceivedOrDateTimeStampInUTC"]) && $aMessage["ReceivedOrDateTimeStampInUTC"] !== '') {
  try {
    $dte  = new DateTimeFrench(date('Y-m-d H:i:s', $aMessage["ReceivedOrDateTimeStampInUTC"]));
    $date = 'Le '.$dte->format("l j F Y H:i");
  }
  catch (Exception $e) { }
}
$body       = isset($aMessage["Subject"]) && $oMessage->getHtml() !== '' ? $oMessage->getHtml() : $oMessage->getPlain();
$flagged    = $aMessage["IsFlagged"] ? 'fas fa-star text-warning' : 'far fa-star text-gray-light';
$pjs        = array();
if(!$aMessage["IsSeen"]) {
  $oMailDecorator->SetMessagesSeen($AccountID, $Folder, $Uid, true);
}
if($aMessage["Attachments"]) {
  $attachments = $aMessage["Attachments"]["@Collection"];
  if(is_array($attachments) && count($attachments) > 0) {
    $path = "pj".DIRECTORY_SEPARATOR.$Uid;
    if (!is_dir($chemin.$path)) { mkdir($chemin.$path); }
    foreach($attachments as $attachment) {
      $FileName   = $attachment["FileName"];
      $FileSize   = $attachment["EstimatedSize"];
      $CID        = $attachment["CID"];
      $IsInline   = $attachment["IsInline"];
      $file       = $path.DIRECTORY_SEPARATOR.$FileName;

      // I need to save the attachments in the $path folder
      if(file_exists($chemin.$file)) {
        if($IsInline) {
          if($CID !== '') {
            $body = preg_replace('/src="cid:'.$CID.'"/', 'src="'.URL_SITE.$file.'"', $body);
          }
        }
        else {
          $path_parts = pathinfo($chemin.$file);
          $infoFile   = infosFileType($path_parts['extension']);
          $pjs[]      = array(
            'size'  => convertFileSize(filesize($chemin.$file)),
            'name'  => cleanString((string) $FileName),
            'ext'   => $path_parts['extension'],
            'ico'   => $infoFile['ico'],
            'type'  => $infoFile['type'],
            'file'  => $FileName
          );
        }
      }
    }
  }
}
Back to Top View pcwebservice's Profile Search for other posts by pcwebservice
 
pcwebservice
Newbie
Newbie
Avatar

Joined: 03 July 2021
Location: France
Online Status: Offline
Posts: 8
Posted: 05 July 2021 at 8:11am | IP Logged Quote pcwebservice

Is it clearer for you with my code?
Back to Top View pcwebservice's Profile Search for other posts by pcwebservice
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6010
Posted: 06 July 2021 at 1:49am | IP Logged Quote Igor

Message object only contains what's needed to display the message itself, it doesn't contain message attachments or their thumbnails, those are downloaded separately. And for download to work, it's necessary to be signed into WebMail; I mean, you can obtain the download URLs - but you need to be logged into WebMail account to actually download the files.

--
Regards,
Igor, Afterlogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 
pcwebservice
Newbie
Newbie
Avatar

Joined: 03 July 2021
Location: France
Online Status: Offline
Posts: 8
Posted: 06 July 2021 at 8:57am | IP Logged Quote pcwebservice

Hello,

Do you have a sample script to connect me to webmail while staying in my application?

This link explains how to connect to webmail by programming, but it redirects to webmail.

And I will just need to login to generate the authentication so that I can use the links.
Back to Top View pcwebservice's Profile Search for other posts by pcwebservice
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6010
Posted: 06 July 2021 at 11:37pm | IP Logged Quote Igor

Quote:
This link explains how to connect to webmail by programming, but it redirects to webmail.


\Aurora\System\Api::Location method call performs the redirect and you can omit that one, you just need Login method to get auth token and then set a cookie with it. Note that your application needs the account's password for this to work, it can be obtained via PHP API as shown here.

--
Regards,
Igor, Afterlogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide