home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 1999 October / PCpro_1999_10.ISO / Tools / wwmfix / Source / Module1.bas < prev   
Encoding:
BASIC Source File  |  1998-07-28  |  8.5 KB  |  259 lines

  1. Attribute VB_Name = "Module1"
  2. Option Explicit
  3.  
  4. Public Const Title = "MailFix"
  5.  
  6. Public Const MailFixIni = "MailFix.ini"
  7. Public Const MailFixRoot = "MailFix.Root"
  8.  
  9. Public Const IniEntryMaxLen = 32000
  10.  
  11. Public Const SectName = "Name"
  12. Public Const SectAdr = "Adresse"
  13. Public Const SectSubj = "Betreff"
  14. Public Const SectText = "Nachricht"
  15.  
  16. Public Const cMsgInvalidChar = "Der Name darf die Zeichen \ / : * ? '' < > | nicht enthalten!"
  17.  
  18. Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
  19. Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
  20. Declare Function fCreateShellLink Lib "vb5STKIT.DLL" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long
  21.  
  22. Public Param() As String
  23. Public LocOptIdx As Integer
  24. Public NewLinkName As String
  25. Public InvalidChars As String
  26.  
  27. Sub Main()
  28.     InvalidChars = "\/:*?<>|" + Chr$(34)
  29.     If Dir(App.Path + "\" + MailFixRoot) = "" Then
  30.         GetParams
  31.         CreateMail
  32.     Else
  33.         Form2.Caption = Title + " - Neue Verknⁿpfung erstellen"
  34.         Form2.Show
  35.     End If
  36. End Sub
  37.  
  38. Sub MakeLink()
  39. Dim StoragePath As String
  40. Dim MailFixExePath As String
  41. Dim LinkLocation As String
  42. Dim rc As Long
  43.     Randomize Timer
  44.     Do
  45.         StoragePath = App.Path + "\" + Right("0000000" + Hex(Rnd * (2 ^ 31)), 8)
  46.     Loop Until Dir(StoragePath, vbDirectory) = ""
  47.     MkDir StoragePath
  48.     MailFixExePath = StoragePath + "\" + App.EXEName + ".exe"
  49.     FileCopy App.Path + "\" + App.EXEName + ".exe", MailFixExePath
  50.     If LocOptIdx Then 'Desktop
  51.         LinkLocation = "..\..\desktop"
  52.     Else 'Sendto
  53.         LinkLocation = "..\..\sendto"
  54.     End If
  55.     rc = fCreateShellLink(LinkLocation, NewLinkName, MailFixExePath, "")
  56.     End
  57. End Sub
  58.  
  59. Sub CreateMail() '*** BEGINNE NEUE MAIL UND ZEIGE DIALOG
  60. Dim i As Long
  61. Dim DateiName As String
  62. Dim DateiNameLang As String
  63. Dim TempAnhangListe As String
  64.     '*** Form vorbereiten
  65.     ReadMailfixData
  66.     Form1.Caption = Title + " - Nachricht erstellen"
  67.     Form1.Show
  68.     '*** Session er÷ffnen
  69.     Form1.MAPISession1.SignOn
  70.     With Form1.MAPIMessages1
  71.         .SessionID = Form1.MAPISession1.SessionID
  72.         '*** Neue Nachricht beginnen
  73.         .Compose
  74.         '*** Alle per DND ⁿbergebenen Dateien anhΣngen
  75.          For i = 1 To UBound(Param)
  76.              DateiName = Param(i) 'Name mit Pfad in Kurzformat
  77.              DateiNameLang = Dir(DateiName) 'Name ohne Pfad im Langformat
  78.              If Len(DateiNameLang) Then  'Nur Dateien erlauben
  79.                 .AttachmentIndex = i - 1    'Att.-Idx setzen
  80.                 .AttachmentPathName = DateiName  'Position der Datei auf Platte
  81.                 .AttachmentName = DateiNameLang  'Name fⁿr Anzeige in Mail
  82.                 TempAnhangListe = TempAnhangListe & i & ": " & DateiNameLang 'Liste fⁿr Dialog
  83.                 If i < UBound(Param) Then TempAnhangListe = TempAnhangListe & vbCr & vbLf
  84.                 .AttachmentType = mapData 'Typ festlegen: alle echte Dateien, keine LInks
  85.              Else
  86.                 '*** Fehlermeldung, falls ein Verz. unter den Attachm. ist
  87.                 MsgBox "Verzeichnisse wie '" + Dir(DateiName, vbDirectory) + "'k÷nnen nicht an eine Nachricht angehΣngt werden.", vbExclamation, Title
  88.             End If
  89.         Next
  90.         Form1.Anhang.Text = TempAnhangListe 'Att.-Liste an Dialog ⁿbergeben
  91.     End With
  92.     ChkSendButtonConditions
  93.     '*** Danach Steuerⁿbergabe an den Dialog
  94.     '*** nach Klick auf [SENDEN] geht bei SendMail weiter....
  95.     
  96. End Sub
  97.  
  98. Sub SendMail() '*** MAIL-DATEN ▄BERNEHMEN UND SENDEN
  99. Dim MailAdresse As String
  100. Dim MailName As String
  101.     With Form1.MAPIMessages1
  102.         '*** EmpfΣngerdaten in Obj. ⁿbernehmen
  103.         .RecipType = mapToList '->TO:
  104.         .AddressResolveUI = False
  105.         MailAdresse = Trim(Form1.EmpfAdr.Text)
  106.         MailName = Trim(Form1.EmpfName.Text)
  107.         If MailName = "" Then 'Kein Name?
  108.             .RecipDisplayName = MailAdresse  'Dann Adresse als Name verw.
  109.         Else
  110.             .RecipDisplayName = MailName '... sonst eben den Namen ⁿbern.
  111.             If MailAdresse = "" Then 'Keine Adresse?
  112.                 .AddressResolveUI = True 'Dann vom Adressbuch auswerten lassen
  113.                 On Local Error GoTo ResolveError 'Evtl. Fehler ausweichen
  114.                 .ResolveName
  115.                 On Local Error GoTo 0
  116.             Else
  117.                 .RecipAddress = MailAdresse 'Adresse war von Anw. gegeben
  118.             End If
  119.         End If
  120.         .MsgSubject = Trim(Form1.Betreff.Text) 'Betreff ⁿbergeben und auch
  121.         .MsgNoteText = Trim(Form1.Nachricht.Text) ' den Nachrichtentext
  122.         '*** Ab damit und zwar direkt ohne zus. Dialog
  123.         .Send False
  124.         WriteMailfixData
  125.         '*** Sitzung schlie▀en und Prg beenden
  126.     End With
  127.     End
  128. ResolveError:
  129.     Resume Next
  130. End Sub
  131.  
  132. Sub ChkSendButtonConditions()
  133.     With Form1
  134.         .Command1(0).Enabled = Trim(.EmpfAdr.Text + .EmpfName.Text) <> ""
  135.     End With
  136. End Sub
  137.  
  138. Sub EndPrg()
  139.         Form1.MAPISession1.SignOff
  140.         End
  141. End Sub
  142.  
  143. Sub GetParams()
  144. ReDim Param(0) As String
  145. Dim s As String
  146. Dim i As Long
  147. Dim a As Long
  148. Dim e As Long
  149.     s = Trim(Command) + " "
  150. FindChar:
  151.     i = i + 1
  152.     If i > Len(s) Then GoTo FindDone
  153.     If Mid(s, i, 1) = " " Then GoTo FindChar
  154.     a = i
  155. FindSpace:
  156.     i = i + 1
  157.     If i > Len(s) Then GoTo FindDone
  158.     If Mid(s, i, 1) <> " " Then GoTo FindSpace
  159.     e = i
  160.     ReDim Preserve Param(1 + (UBound(Param))) As String
  161.     Param(UBound(Param)) = Mid(s, a, e - a)
  162.     GoTo FindChar
  163. FindDone:
  164. Debug.Print
  165. For i = 1 To UBound(Param)
  166.     Debug.Print "Param(" & i & ")='" & Param(i) & "'"
  167. Next
  168. End Sub
  169.  
  170. Function DecodeBackSlashStr(s1 As String) As String
  171. Dim s2 As String
  172. Dim c As String
  173. Dim i As Long
  174. Dim XlatFlag As Boolean
  175.     For i = 1 To Len(s1)
  176.         c = Mid(s1, i, 1)
  177.         If XlatFlag Then
  178.             Select Case UCase(c)
  179.                 'Case "\"
  180.                     Rem --> bleibt "\"
  181.                 Case "N"
  182.                     c = vbCr
  183.                 Case "L"
  184.                     c = vbLf
  185.             End Select
  186.             XlatFlag = False
  187.         Else
  188.             XlatFlag = (c = "\")
  189.         End If
  190.         If Not XlatFlag Then s2 = s2 & c
  191.     Next
  192.     DecodeBackSlashStr = s2
  193. End Function
  194.  
  195. Function EncodeBackSlashStr(s1 As String) As String
  196. Dim s2 As String
  197. Dim c As String
  198. Dim i As Long
  199.     For i = 1 To Len(s1)
  200.         c = Mid(s1, i, 1)
  201.         Select Case c
  202.             Case vbLf
  203.                 c = "\L"
  204.             Case vbCr
  205.                 c = "\N"
  206.         End Select
  207.         s2 = s2 + c
  208.     Next
  209.     EncodeBackSlashStr = s2
  210. End Function
  211.  
  212. Public Sub WriteIni(SubSection As String, ByVal s As String)
  213. Dim rc As Long
  214.     rc = WritePrivateProfileString(Title, SubSection, s, App.Path + "\" + MailFixIni)
  215. End Sub
  216.  
  217. Public Function ReadIni(SubSection As String) As String
  218. Dim s As String
  219.     s = Space(IniEntryMaxLen)
  220.     ReadIni = Left(s, GetPrivateProfileString(Title, SubSection, "", s, Len(s), App.Path + "\" + MailFixIni))
  221. End Function
  222.  
  223. Sub WriteMailfixData()
  224.     WriteIni SectName, Form1.MAPIMessages1.RecipDisplayName
  225.     WriteIni SectAdr, Form1.MAPIMessages1.RecipAddress
  226.     WriteIni SectSubj, Form1.Betreff.Text
  227.     WriteIni SectText, EncodeBackSlashStr(Form1.Nachricht.Text)
  228. End Sub
  229.  
  230. Sub ReadMailfixData()
  231.     Form1.EmpfName.Text = ReadIni(SectName)
  232.     Form1.EmpfAdr.Text = ReadIni(SectAdr)
  233.     Form1.Betreff.Text = ReadIni(SectSubj)
  234.     Form1.Nachricht.Text = DecodeBackSlashStr(ReadIni(SectText))
  235. End Sub
  236.  
  237. Function NewLinkNameOk() As Boolean
  238. Dim i As Long
  239. Dim rc As Boolean
  240.     For i = 1 To Len(NewLinkName)
  241.         If InStr(InvalidChars, Mid(NewLinkName, i, 1)) Then
  242.             rc = True
  243.             Exit For
  244.         End If
  245.     Next
  246. NewLinkNameOk = Not rc
  247. End Function
  248.  
  249. Public Sub ShowInfo()
  250.     MsgBox Title + " - E-Mails einfach per Drag-n-Drop erstellen." + _
  251.         vbCr + vbCr + "⌐ 1998 by Wolfgang Wirth" + vbCr + vbCr + _
  252.         "'VerbesserungsvorschlΣge und konstruktive" + vbCr + _
  253.         "Kritik sind mir immer willkommen!'" + vbCr + vbCr + _
  254.         "E-Mail: ToolMaker@Iname.com" + vbCr + vbCr + _
  255.         "Web: Perso.wanadoo.fr/wolfgang.wirth", 64, Title
  256. End Sub
  257.  
  258.  
  259.