extract Outlook Attachments

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
danielmaximiliano
Posts: 2647
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: extract Outlook Attachments

Post by danielmaximiliano »

Code: Select all

IF cCopyMove = "MOVE" 
           //  While myattachments.Count > 0 
           //     myattachments.Remove 1 
           //  Wend 
            DO WHILE oAttachment:Count > 0
               oAttachment:Remove(1)
            ENDDO
         ENDIF

Code: Select all

       If xMailItem.Attachments.Count > 0 Then
            For I = xMailItem.Attachments.Count To 1 Step -1
                Set xAttachment = xMailItem.Attachments.Item(I)
                xFileType = xFSO.GetExtensionName(xAttachment.FileName)
                If InStr(xFileType, Trim(xType)) > 0 Then
                    xAttachment.Delete  //Try
                End If
            Next I
            xMailItem.Save    // Try
        End If
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
AUGE_OHR
Posts: 2108
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: extract Outlook Attachments

Post by AUGE_OHR »

danielmaximiliano wrote: Sat Apr 25, 2020 4:01 am Copy Work
Jimmy, do you want to delete all attachments after moving the downloaded files?
because I see that they are still in the inbox
YES ... but as you say it seem still in Outlook

Code: Select all

               IF cCopyMove = "COPY" .OR. cCopyMove = "MOVE"
                  IF FILE( cOut + cName )
                     FERASE( cOut + cName )
                  ENDIF
                  // this work
                  oAttachment:Item( i ):SaveAsFile( cOut + cName )

                  IF cCopyMove = "MOVE"
                     // hm ... no Error but seems not to work   
                     oAttachment:Item( i ):Delete()
                  ENDIF
               ENDIF
Methode SaveAsFile() and Delete() are from same Object
https://docs.microsoft.com/en-us/office ... saveasfile
https://docs.microsoft.com/en-us/office ... ent.delete

so i´m confused why it don´t work :(
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2108
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: extract Outlook Attachments

Post by AUGE_OHR »

got it :D

in your Sample and your link i saw "Save" ... that was the missing part after delete Attachment :lol:

p.s. when Attachment have same Name it will be override ...
have fun
Jimmy
User avatar
danielmaximiliano
Posts: 2647
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: extract Outlook Attachments

Post by danielmaximiliano »

It was as I thought :ugeek: , an Email contains an attachment, when deleting that attachment you have to save the email again without the .. since the Email container does not know that this attachment was deleted until it is updated.

you can paste to update code
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
AUGE_OHR
Posts: 2108
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: extract Outlook Attachments

Post by AUGE_OHR »

danielmaximiliano wrote: Sat Apr 25, 2020 10:41 pm It was as I thought :ugeek: , an Email contains an attachment, when deleting that attachment you have to save the email again without the .. since the Email container does not know that this attachment was deleted until it is updated.
not sure if it "real" work ... size of Outlook.PST still same Size (after compress) :o
danielmaximiliano wrote: Sat Apr 25, 2020 10:41 pm you can paste to update code
i have change ":DisplayName" to "FileName" which Name is "save-able"

Code: Select all

   nStart := SECONDS()
   nMax := oFolder:items:count
   FOR n := 1 TO nMax
      oMailItem := oFolder:Items( n )

      bOldError := ERRORBLOCK( { | e | BREAK( e ) } )
      BEGIN SEQUENCE
         oAttachment := oMailItem:Attachments
         nCount := oAttachment:Count
      END SEQUENCE
      ERRORBLOCK( bOldError )

      IF nCount > 0
         IF cCopyMove <> "NO"
            cSubj := SUBSTR( oMailItem:Subject, 1, 80 ) + CRLF
            OLATTACH.List_Out.Additem( cSubj )
         ENDIF

         i := 1
         FOR i := nCount TO 1 STEP - 1
            bOldError := ERRORBLOCK( { | e | BREAK( e ) } )
            BEGIN SEQUENCE
               //  oItem := oAttachment:Item( i )
               //  cName := oAttachment:Item( i ):DisplayName
               cName := oAttachment:Item( i ) :FileName
               nSize := oAttachment:Item( i ) :Size

               IF cCopyMove <> "NO"
                  // per Reference
                  CheckDupe( @cName, nSize )
                  OLATTACH.List_Out.Additem( cName )
               ENDIF
               nSum ++

               IF cCopyMove = "COPY" .OR. cCopyMove = "MOVE"
                  IF FILE( cOut + cName )
                     FERASE( cOut + cName )
                  ENDIF
                  oAttachment:Item( i ) :SaveAsFile( cOut + cName )
               ENDIF

            END SEQUENCE
            ERRORBLOCK( bOldError )
         NEXT

         IF cCopyMove = "MOVE"
            i := 1
            FOR i := nCount TO 1 STEP - 1
               oAttachment:Item( i ) :Delete()
            NEXT
            // NEED to save
            oMailItem:Save()
         ENDIF

         IF cCopyMove <> "NO"
            OLATTACH.List_Out.Additem( "----------------------------------" )
         ENDIF
         OLATTACH.List_Out.Value := OLATTACH.List_Out.ItemCount
      ENDIF

      SetProperty( "OLATTACH", "ProgressBar_1", "Value", CalcPos( n, nMax ) )

   NEXT

   OLATTACH.ProgressBar_1.Value := 0
   nStop := SECONDS()
have fun
Jimmy
Post Reply