home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / po7_win / db / rdbms71 / utlmail.sql < prev    next >
Text File  |  1994-08-07  |  6KB  |  179 lines

  1. rem 
  2. rem $Header: utlmail.sql 7010200.1 93/11/15 00:13:45 snataraj Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) 1991 by Oracle Corporation 
  5. Rem    NAME
  6. Rem      utlmail.sql - upgrade mail database for access from rpc
  7. Rem    DESCRIPTION
  8. Rem      Upgrade the mail database with the appropriate user, views and
  9. Rem      privs so that the dbms_mail pl/sql package can be used to send email.
  10. Rem
  11. Rem    NOTE: Run this script as user "email".
  12. Rem
  13. Rem      The password of the email account of this database need not 
  14. Rem      be divulged.
  15. Rem   
  16. Rem      There needs to be an user in this database (e.g., rmail/rmail)
  17. Rem      so that the package "dbms_mail" can be created.
  18. Rem     This account should only have "connect" privilege.  This account
  19. Rem     name and password will need to be given to the installer of the
  20. Rem     "dbms_mail" package so that they can create appropriate database
  21. Rem     links.
  22. Rem
  23. Rem      This user also needs to be a valid Oracle*Mail user.  For example,
  24. Rem      create user rmail as follows:
  25. Rem
  26. Rem         create user rmail identified by rmail;
  27. Rem         grant connect to rmail;
  28. Rem
  29. Rem        <now add rmail as a valid Oracle*Mail user>
  30. Rem    
  31. Rem     NOTE:  If you run this script multiple times, you will get an error
  32. Rem    regarding the creation of the sequence "m_id_seq" since it already
  33. Rem    exists.  This error message is *OK*.  Do NOT drop this sequence 
  34. Rem    once created.  If you do, and recreate it, you will then get 
  35. Rem    DUPLICATE mail ids.
  36. Rem
  37. Rem    RETURNS
  38. Rem 
  39. Rem    NOTES
  40. Rem      
  41. Rem    MODIFIED   (MM/DD/YY)
  42. Rem     rkooi      04/20/93 -  various P3 and P4 bugs (improved comments)
  43. Rem     mmoore     02/05/93 - #(149230) use create user instead of grant 
  44. Rem     glumpkin   10/20/92 -  Renamed from MAILUPGD.SQL 
  45. Rem     rkooi      09/30/92 -  add s_user_name view
  46. Rem     fnazem,rkooi  01/22/92 -  Creation 
  47.  
  48. Rem ===== S_SENDER_INFO =====
  49.  
  50. Rem  "s_user_name" is used by the client to determine if it is using an 
  51. Rem  anoymous dblink, or a dblink with name and password.
  52.  
  53. drop view s_user_name
  54. /
  55. create view s_user_name (user_name) as select user from dual
  56. /
  57. grant select on s_user_name to public
  58. /
  59.  
  60. drop view s_sender_info
  61. /
  62.  
  63. Rem  Provide sender information to the remote sending database. 
  64. Rem  This view is also used by the views defined below to ensure that
  65. Rem  sender_id corresponds the the actual sender.
  66.  
  67. create view s_sender_info (name, sender_name, msg_node, user_id, 
  68.     user_node) as
  69.   select user_name, user_name||'.'||domain_name, node_id+1000000000,
  70.     user_id, user_node
  71.   from email.m_user_info u, email.m_domain d, email.m_cur_node c
  72.   where d.domain_id=c.domain_id and u.domain_id=c.domain_id 
  73.     and user_name=user and ua_node=node_id
  74. /
  75. grant select on s_sender_info to public
  76. /
  77.  
  78. Rem ====== V_SEND_HEADER, S_SEND_HEADER ======
  79.  
  80. drop view s_send_header
  81. /
  82. drop view v_send_header
  83. /
  84.  
  85. Rem  v_send_header enforces various integrity constraints
  86. Rem  s_send_header disallows selects while still allowing the
  87. Rem     "select */describe" needed for access from remote database
  88.  
  89. create view v_send_header (msg_id, msg_node, type, part_type, hdr_flags,
  90.     sender_id, sender_node, sender_date, reply_to, to_str, cc_str, bcc_str,
  91.     subject, from_str, sender_name, deferred, inclusion_id, inclusion_node)
  92.   as
  93.   select msg_id, msg_node, type, part_type, hdr_flags, sender_id,
  94.     sender_node, sender_date, reply_to, to_str, cc_str, bcc_str, subject,
  95.     from_str, sender_name, deferred, inclusion_id, inclusion_node
  96.   from email.m_header h
  97.   where type=1 and part_type=0 and hdr_flags=0 and inclusion_id=0
  98.     and inclusion_node=0 and deferred='N' and exists
  99.     (select 1 from email.s_sender_info s
  100.      where s.sender_name=h.sender_name and s.msg_node=h.msg_node
  101.        and s.user_id=h.sender_id and s.user_node=h.sender_node)
  102.   with check option
  103. /
  104. create view s_send_header as select * from v_send_header where 1=0
  105. /
  106. Rem need select in order to be able to insert from remote node
  107. grant select,insert on s_send_header to public
  108. /
  109.  
  110. Rem ====== V_SEND_BODY, S_SEND_BODY ======
  111.  
  112. drop view s_send_body
  113. /
  114. drop view v_send_body
  115. /
  116.  
  117. Rem  v_send_body enforces various integrity constraints
  118. Rem  s_send_body disallows selects while still allowing the
  119. Rem     "select */describe" needed for access from remote database
  120.  
  121. create view v_send_body (msg_id, msg_node, part, order_no, msg_line) as
  122.   select msg_id, msg_node, part, order_no, msg_line
  123.   from email.m_body b
  124.   where part=0 and exists
  125.     (select 1
  126.       from email.m_instance i, email.m_header h, email.s_sender_info s
  127.       where h.msg_id=b.msg_id and h.msg_node=b.msg_node
  128.        and i.msg_id=b.msg_id and i.msg_node=b.msg_node and folder_id=2
  129.        and s.user_id=h.sender_id and s.user_node=h.sender_node)
  130.   with check option
  131. /
  132. create view s_send_body as select * from v_send_body where 1=0
  133. /
  134. Rem need select in order to be able to insert from remote node
  135. grant select,insert on s_send_body to public
  136. /
  137.  
  138. Rem ====== V_SEND_INSTANCE, S_SEND_INSTANCE ======
  139.  
  140. drop view s_send_instance
  141. /
  142. drop view v_send_instance
  143. /
  144.  
  145. Rem  v_send_instance enforces various integrity constraints
  146. Rem  s_send_instance disallows selects while still allowing the
  147. Rem     "select */describe" needed for access from remote database
  148.  
  149. create view v_send_instance (msg_id, msg_node, node_id, msg_owner,
  150.     folder_id, retention_date, unread_flag, flags) as
  151.   select msg_id, msg_node, node_id, msg_owner, folder_id, retention_date,
  152.     unread_flag, flags
  153.   from email.m_instance i
  154.   where folder_id=2 and unread_flag='Y' and flags=0 and exists
  155.     (select 1 from email.m_header h, email.s_sender_info s
  156.       where h.msg_id=i.msg_id and h.msg_node=i.msg_node
  157.        and s.user_id=h.sender_id and s.user_node=h.sender_node
  158.        and s.user_id=i.msg_owner and s.user_node=i.node_id)
  159.   with check option
  160. /
  161. create view s_send_instance as select * from v_send_instance where 1=0
  162. /
  163. Rem need select in order to be able to insert from remote node
  164. grant select,insert on s_send_instance to public
  165. /
  166.  
  167. Rem ====== M_ID_SEQ ======
  168.  
  169. Rem  use sequence to get the mail id.  This is because the updates to 
  170. Rem  this database may be part of a distributed transaction and we don't want
  171. Rem  to lock out other mail senders for the duration of that transaction
  172. Rem  NOTE:  Do NOT drop this sequence once created.  If you do, and
  173. Rem  recreate it, you will then get DUPLICATE mail ids.
  174.  
  175. create sequence email.m_id_seq start with 10000
  176. /
  177. grant select on email.m_id_seq to public
  178. /
  179.