Solved

[Lotusscript] Extracting same-name attachments

Posted on 2004-09-16
14
2,159 Views
Last Modified: 2013-12-18
I have an e-mail with 2 attachments, and both of the attachments are named File.TIF.  

When I do the following...
Forall eo In rtitem.EmbeddedObjects
  If (eo.Type = EMBED_ATTACHMENT) Then
     i = i + 1
     Call eo.ExtractFile(i & eo.Source)
  End If
End Forall
... I get 1File.TIF and 2File.TIF, but they are exactly the same, in other words, 1File.TIF is the first attachment and 2File.TIF is also the first attachment!

When I do the following...
v2FileNames = Evaluate("@AttachmentNames", doc)
For i = Lbound(v2FileNames) To Ubound(v2FileNames)
  Set attachedFile = doc.getAttachment(v2FileNames(i))
  Call attachedFile.extractFile(i &  v2FileNames(i))
Next  
... I get a 1File.TIF and an ATTCCDWY file, and they are the two attachments which is good.  But there is no file extension on the second file and I need to know what it is.

I'm not much of a Lotusscripter, never been trained in it, and don't have the resources or time to figure this out.  So 500 points to someone who can provide a routine which will extract and create 1File.TIF and 2File.TIF, or 1File.TIF and ATTCCDWY.TIF, or similar.  Bear in mind that e-mails I will be extracting from can have any number of attachments (that is, not limited to 2), any attachment names (that is, not necessarily File.TIF), any attachment extensions (that is, not always TIF), and any mixture of extensions (that is, TIF, XLS, DOC, PDF in the same email).
0
Comment
Question by:Xinger
  • 4
  • 3
  • 2
  • +3
14 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 12078396
Try renaming every attachment, using
    Name oldname As newname
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 12078416
So
    Forall eo In rtitem.EmbeddedObjects
      If (eo.Type = EMBED_ATTACHMENT) Then
         i = i + 1
         Call eo.ExtractFile(eo.Source)
         Name eo.source As ("1" & eo.source)
      End If
    End Forall
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 12078759
This should do the trick for you.

Dim doc as NotesDocument

' Set the value of doc

Forall eo In doc.EmbeddedObjects
 If (eo.Type = EMBED_ATTACHMENT) Then
    i = i + 1
    Call eo.ExtractFile(i & eo.Source)
  End If
End Forall



I have just changed the rtitem to doc. It should work. If it doesn't (still gives last file name w/o extension) please verify that the sender/creator actually attached/created with those names. DO a sample test and please let us know.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 14

Expert Comment

by:p_partha
ID: 12079040
When you attach the same filename twice, the second attachment will get a randomly generated internal filename (this is notes behaviour) but i have seen cases where you loose the file extension , and as far as i know i didn't find any way to programatically get at the original filename

Partha
0
 

Author Comment

by:Xinger
ID: 12079323
Sorry to be slow in responding; got other priorities hitting me right now.

sjef_bosman:  I have not tried this yet; have you tried this or is this just a suggestion?

RanjeetRain:  this looks exactly the same as the original code I posted except that I did not show you that I am setting the value of doc.  Is this the change you are suggesting?  I have not tried this yet; have you tried this or is this just a suggestion?

Partha:  I was hoping this isn't true.  I don't doubt you, but I'll wait for other comments to validate this.
0
 

Author Comment

by:Xinger
ID: 12079349
RanjeetRain, I apologize.  I just now saw your explanation at the end of your comment.  Thanks.
0
 
LVL 15

Expert Comment

by:Bozzie4
ID: 12081663
Partha is correct, when adding 2 files with the same name to 1 document, INTERNALLY, the filename changes.   But you can see this easily using @Attachmentnames, I think this gives you the name that Notes uses internally to refer to the document.

cheers,

Tom
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 12082883
Eh, it was only a suggestion. Just checked it, and it doesn't work. :(
0
 
LVL 15

Expert Comment

by:Bozzie4
ID: 12082968
If doc.HasEmbedded Then
            Forall i In doc.Items
                  If i.type = Attachment Then
                        Set nitem = doc.GetFirstItem(i.name)
                        Set o = doc.GetAttachment(i.values(0))
                        filename = "/tmp/"+o.source
                        Call o.extractfile(filename)
                        End If
            End Forall
            
      Else
            Error 12346, "no attachments"
      End If

Now to solve the naming issue, that's trickier.  You need to know which of the 2, the original name was.    If it's enough to see it it has an extension, you could do something like
if instr(i.values(0), ".") > 0 then
' yes
' store this name as name to use
else
' no
' rename this 1 when writing to disk
end if
0
 

Author Comment

by:Xinger
ID: 12129432
I found the solution on my own:

Forall eo In rtitem.EmbeddedObjects
      If (eo.Type = EMBED_ATTACHMENT) Then
            ' If Name and Source are different, Name is a random name assigned by Domino...
            If eo.Name <> eo.Source Then
                  ' take advantage of the random Name & add extension of the Source...
                  attname = eo.Name & "." & GetExtension(eo.Source)
            Else
                  ' No random name was assigned, so it is safe to use Source...
                  attname = eo.Source
            End If
            Call eo.ExtractFile(attname)
      End If
End Forall

0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 12147180
Good if this code has sorted out your problem. But Name property of NotesEmbeddedObject class is valid only for Embedded objects and not for file attachments. For file attachments this property always returns a blank string. So, my conclusion is this code might have worked for you in a test environment but it will not work if you have 3-4 attachments of same file name.
0
 

Author Comment

by:Xinger
ID: 12147551
Thanks for the heads up on this.  I see that it is documented this way, but I have not expereinced this.  I ran dozens of tests, and I made sure to include an e-mail with 4 pairs of same-named attachments.  The Name property has never been blank, and I have always seen a non-empty Name in the debugger in all situations.  But since you brought it to my attention, I will be wary, and also pursue a verification.  For now, I'm sticking with the code assuming it will work.  Thanks.
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 12160283
Closed, 500 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Lotus Notes 41 197
Lotus Notes Mail Database issues 2 919
Problem setting value in rich text field with action 11 57
Lotus Notes shared mailbox 'Sent by' in header 3 66
This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now